Announcement

Collapse
No announcement yet.

GDIPlus Draw Image Gotcha

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • GDIPlus Draw Image Gotcha

    I am currently working on yet another GDIPlus Image Viewer (but it will do what I want in the way I want). It is not ready yet to post.

    However, I have found that if the image you want to display has specified pixels per inch (or per meter, cm, etc.)
    and that setting does not match your display dpi setting, the simple GDipDrawImage or GdipDrawImageI will scale
    either smaller or larger (and cropped to the window size).
    I am on Win7 Prof 64-bit and have a dpi setting at the default 96 dpi.
    If the image file does not specify dpi, it works as expected.

    Assuming 96 dpi, if the image has specified e.g. 192 dpi (double) the image will be shrunk to the top left quarter
    of the window.
    If it specified 48 dpi, the display will be double sized and cropped to the top left quarter of the image.
    These exact values are unlikely in the wild, but serve to demonstrate the nature of the scaling.
    In example from my own files, scale ups or downs of approx 30% were seen.

    All the code I looked at while researching GDIPlus Flat API (on these very forums -- thanks guys) used plain
    old DrawImage.

    I am assuming that you have created a window or graphic window or graphic bitmap that is the exact size of the image
    The work around is to use GdipDrawImageRect or GdipDrawImageRectI.
    This is almost the same as DrawImage, but takes additional parameters for width and height.
    You just have to give it the image (and window) width and height.

    Code:
            GdipDrawImageRectI(graphic, image, 0, 0, width, height)
    Cheers, Mike.
    There are only two speeds for computers: fast enough, and too bloody slow.
    And there are 10 types of programmer -- those that know binary, and those that don't.
Working...
X