Jump to content

GDI+ DrawImage Stretches Unwanted

- - - - -

  • Please log in to reply
3 replies to this topic

#1
TheMatrixUnicef

TheMatrixUnicef

    Newbie

  • Members
  • Pip
  • 2 posts
Hi buddies.
My English is terrible so plz dont panic (if u found grammatical errors).
I've just made a program that uses GDI+ functions to simply load an image from disk and display it onto the window.
the code is very simple:
Graphics graphics(hdc);

Image image(L"C:\\1.bmp");

graphics.DrawImage(&image,0,0);
but the problem is that the drawimage function, acts stupidly!
That when i just load a file (bmp or png) created using Paint (Windows Application), it shows it correctly, but when i create the same image with Photoshop n save it as a bmp, the program resizes my image by 4/3 ratio (stretches it)!
i dunno what's the matter, i'd be grateful if anyone tell how to fix this problem.
i guess its the matter of color channels but dunno howto tell the Image Object treating normally with different Color Channel formats!

#2
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 762 posts
Well, this maybe stupid suggestion, but first you have to confirm that you had saved the images in the same dimension both when used paint and when used Photoshop.

If you know that you had saved them in the same dimension, then perhaps you can check the color/bit depth you had used when saved them. Some version of Paint I believe does not offer obvious selection of color depth when saving, while photoshop always does when saving as windows bitmap. Maybe they were different.

Other than that, the only possible reason I can think of is dpi information. So don't forget to check it out.

#3
TheMatrixUnicef

TheMatrixUnicef

    Newbie

  • Members
  • Pip
  • 2 posts
U mean that the GDI+ is DPI-aware itself?

#4
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 762 posts

TheMatrixUnicef said:

U mean that the GDI+ is DPI-aware itself?

Actually I don't know it for sure. In Windows XP and prior Windows it was not DPI aware. But MS had introduced a lot of improvements on this area from Vista and above. So it's a possibility (although it was a very small one). Other than dpi-related (if the dimensions and color depth are the same), honestly I don't have any idea.

The other possible cause that I can think of is that your GDI+ call uses windows api StretchBlt. But I think it's very unlikely, since StretchBlt requires destination's and target's area (rectangle) information, and your code does not give them.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users