Groups | Blog | Home
all groups > dotnet drawing api > january 2005 >

dotnet drawing api : GDI+ FAQ: Problem with best-fit transform and JPEG image


Greg Chapman
1/24/2005 6:46:20 AM
I compiled and ran the sample code from the GDI+ FAQ found here:

http://www.bobpowell.net/bestfit.htm

The program worked correctly for GIF and BMP files, but when I tried a JPG, it
appeared to translate, but not scale (the height of the image I was using was
roughly twice that of the form: only the top half of the image was visible). Is
this a known problem with JPEG files? Is there a workaround?

Thanks.

---
Greg Chapman
Greg Chapman
1/24/2005 1:27:38 PM
On Mon, 24 Jan 2005 17:33:23 +0100, "Bob Powell [MVP]"
[quoted text, click to view]

Thanks! That fixed it. By the way, both the Horizontal and VerticalResolution
are 72 for the image I was testing. My screen resolution
(GetDeviceCaps(,LOGPIXELSY)) is 120. I gather that the simple (3 param)
DrawImage will cause problems whenever these are different? (I gather that
because I found a Jpeg with 120x120 resolution, and that displayed correctly
using the 3 param DrawImage).

---
Greg Chapman
Bob Powell [MVP]
1/24/2005 5:33:23 PM
Try changing the last line of the paint handler to:

e.Graphics.DrawImage(_image,new
Rectangle(0,0,_image.Width,_image.Height),0,0,_image.Width,_image.Height,GraphicsUnit.Pixel);

It may be that the resolution on the JPEG is set to something odd that is
messing up the draw command.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]

AddThis Social Bookmark Button