none
Imaging: When drawing parts of an image, where the part comes from depends on the kind of image

    Dotaz

  • I’m trying to use IImage:: Draw to draw only a part of an image by passing a valid source rectangle as the third parameter. All along I had noticed that the coordinate system was strange, but I went along with it. Going horizontally is fine, but going vertically is treated kind of like flipping the Y direction. The following code adjusts the source rectangle:
     

    Code Snippet
        srcRectUnscaled = *pSrcRect;
        srcRectUnscaled.top = imageInfo.Height - srcRectUnscaled.top;
        srcRectUnscaled.bottom = imageInfo.Height - srcRectUnscaled.bottom;
     
        LONG    bottom = srcRectUnscaled.bottom;
        srcRectUnscaled.bottom = srcRectUnscaled.top;
        srcRectUnscaled.top = bottom;

     

     

    Recently, I tried running the same drawing code for a different bitmap (both were PNG) that only drew fine when the code above was left out and so the Y axis was not flipped. I noticed that the difference between the two images was that one had the following properties and the other didn’t:
     
    -          ImageInfo.Flags has ImageFlagsHasAlpha and ImageFlagsHasTranslucent
    -          ImageInfo.PixelFormat has PixelFormatAlpha and PixelFormatCanonical
     
    Since they both have the flag SinkFlagsTopDown, I don’t see a reason why alpha seems to change the coordinate system of the image. I even tried locking the bits of each image and copying them to a handmade BMP. The resulting BMPs have the same orientation: upside-down. After figuring out the problem with PartiallyScalable and non-96 dpi, this is my last problem.
     
    I know I can try working around this by drawing the whole image to an HBITMAP and taking pieces from there, but I’d rather not. Working around it like that takes up a lot of memory, as seen by the fact that an image that used to draw just fine no longer does, because the system ran out of memory. Also, in the future we might need to draw parts of a translucent image.
     

    I saw the following thread touch on the subject at the end, but the last post was not very assuring. The poster seems to get the same result as me, but it doesn't prove that alpha controls the "orientation".

    Displaying images using IImage - SRC rectangle ?
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=763204&SiteID=1

     

    In summary, how do I use the Imaging API to reliably draw a part of an image, no matter the kind of image, without using more resources than necessary?

      Aldo Nunez

    14. listopadu 2008 20:04

Všechny reakce