Groups | Blog | Home
all groups > dotnet drawing api > december 2003 >

dotnet drawing api : DrawImage Strange srcRect


anonymous NO[at]SPAM discussions.microsoft.com
12/29/2003 7:31:31 AM
Hi,

It seems that nobody talk about this problem before. So
it may be a problem of mine.
When I use the void Graphics.DrawImage(Image image,
Rectangle destRect,
Rectangle srcRect,
GraphicsUnit srcUnit
);

if the size of the srcRect is different from the destRect
I must reduce from 1 pixel srcRect.Width and
srcRect.Height.
So what I have to do is

if(destRect.Size!=srcRect.Size)
{
srcRect=new Rectangle
(srcRect.X,srcRect.Y,srcRect.Width-1,srcRect.Height-1);
}

If someone encounter this pb tell me please.

JHornick NO[at]SPAM online.microsoft.com
12/29/2003 6:14:19 PM
Hi,

Why do you "have to" do this? What bad thing happens if you don't?

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.



[quoted text, click to view]
anonymous NO[at]SPAM discussions.microsoft.com
12/30/2003 2:25:41 AM
More about the Problem in Stretching

For example if you want to create a sp=E9cific button that=20
have an original look like in XP. You have to use a=20
Bitmap with a small Size that you stretch part by part.=20
Il you have a look in the Theme resouces you have the=20
Sizing magins used to stretch an XP theme button describe=20
in the ****_INI. The srcRect is a part of the original=20
bitmap and is stretched depending of the final Size. For=20
example the midle top of a bitmap button in XP is only=20
streched in Width but not in Height to keep the aspect.=20
That is what I am doing and how I discovered this Problem.

But in a general case when you use:

Graphics.DrawImage(Image image,
Rectangle destRect,
Rectangle srcRect,
GraphicsUnit srcUnit
);

If you want to STRETCH and only in this case, a part of=20
it or the complete source image. the srcRect.Size must be=20
reduced in 1 pixel in Width and in Height.

To demonstrate this probleme create a bitmap 30*15 with=20
multiple rectangle one inside the other with different=20
colors. Where line have one pixel width.

First try this:

Rectangle destRect=3Dnew Rectangle(10,10,700,550);
Rectangle srcRect=3D new Rectangle
(0,0,myBitmap.Width,myBitmap.Height);

//in this mode it is more easy to see the pb
gfx.InterpolationMode=3DInterpolationMode.NearestNeighbor;
gfx.DrawImage(myBitmap,
destRect,
srcRect,
GraphicsUnit.Pixel
);

The result is a strange color at the botom and right of=20
the final bitmap.

But if you do the same with
Rectangle srcRect=3D new Rectangle(0,0,myBitmap.Width-
1,myBitmap.Height-1);

The result is correct. And because you have one pixel=20
color different rectangle in the source bitmap, you will=20
be able to constat that the last rectangle is included in=20
the srcRect as strange as it can be!!!!!!

But now don't you use this function for strech you lose=20
one pixel.=20

In a second case :
try with:
Rectangle srcRect=3D new Rectangle(4,4,22,7);
Even if the source rectangle is the good coordonate of a=20
source rectangle the result is not and you must do
Rectangle srcRect=3D new Rectangle(4,4,22-1,7-1);

Now i assume that my english in not very good and I=20
prepared a litle program tha demonstrate the fact. If you=20
want me to send it to you it will be a pleasure.

Best regards






AddThis Social Bookmark Button