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.
John Hornick [MSFT] - 29 Dec 2003 18:14 GMT
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.
> It seems that nobody talk about this problem before. So
> it may be a problem of mine.
[quoted text clipped - 16 lines]
>
> If someone encounter this pb tell me please.
More about the Problem in Stretching
For example if you want to create a spécific button that
have an original look like in XP. You have to use a
Bitmap with a small Size that you stretch part by part.
Il you have a look in the Theme resouces you have the
Sizing magins used to stretch an XP theme button describe
in the ****_INI. The srcRect is a part of the original
bitmap and is stretched depending of the final Size. For
example the midle top of a bitmap button in XP is only
streched in Width but not in Height to keep the aspect.
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
it or the complete source image. the srcRect.Size must be
reduced in 1 pixel in Width and in Height.
To demonstrate this probleme create a bitmap 30*15 with
multiple rectangle one inside the other with different
colors. Where line have one pixel width.
First try this:
Rectangle destRect=new Rectangle(10,10,700,550);
Rectangle srcRect= new Rectangle
(0,0,myBitmap.Width,myBitmap.Height);
//in this mode it is more easy to see the pb
gfx.InterpolationMode=InterpolationMode.NearestNeighbor;
gfx.DrawImage(myBitmap,
destRect,
srcRect,
GraphicsUnit.Pixel
);
The result is a strange color at the botom and right of
the final bitmap.
But if you do the same with
Rectangle srcRect= new Rectangle(0,0,myBitmap.Width-
1,myBitmap.Height-1);
The result is correct. And because you have one pixel
color different rectangle in the source bitmap, you will
be able to constat that the last rectangle is included in
the srcRect as strange as it can be!!!!!!
But now don't you use this function for strech you lose
one pixel.
In a second case :
try with:
Rectangle srcRect= new Rectangle(4,4,22,7);
Even if the source rectangle is the good coordonate of a
source rectangle the result is not and you must do
Rectangle srcRect= new Rectangle(4,4,22-1,7-1);
Now i assume that my english in not very good and I
prepared a litle program tha demonstrate the fact. If you
want me to send it to you it will be a pleasure.
Best regards