C# winforms: graphics.DrawImage problem
Posted
by Tony
on Stack Overflow
See other posts from Stack Overflow
or by Tony
Published on 2010-04-21T09:48:51Z
Indexed on
2010/04/21
9:53 UTC
Read the original article
Hit count: 491
Hi, I have a really strange problem with Graphics.DrawImage method.
I have the PictureBox control in the Panel control with AllowScroll property = true. The program cuts the image on small parts basing on the area selected by the user.
I load the image 300x547 and select the area (the red rectangle):
program properly cuts the image:
then, I load another image 427x640:
and then, as the result I see that the image is not cut properly. Each img.jpg file has properly width & height but the drawn image is too small:
here's the code snippet - it saves the bitmap area selected by the user:
Bitmap bmp = new Bitmap(selectedAreaRECT.Width, selectedAreaRECT.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(OriginalIMG, 0,0, selectedAreaRECT, GraphicsUnit.Pixel);
g.Save();
g.Dispose();
bmp.Save(AppDomain.CurrentDomain.BaseDirectory + @"\Temp\" + "img1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
As You see, the code is the same for the img1.jpg from image A and from Image B. I'm trying to resolve that stupid problem for too long, I don't know what's the reason of that problem. I tried diffrent constructors of the DrawImage method, with no success
© Stack Overflow or respective owner