sexta-feira, 14 de novembro de 2008 20:04
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 SnippetsrcRectUnscaled = *pSrcRect;
srcRectUnscaled.top = imageInfo.Height - srcRectUnscaled.top;
srcRectUnscaled.bottom = imageInfo.Height - srcRectUnscaled.bottom;
LONG bottom = srcRectUnscaled.bottom;
srcRectUnscaled.bottom = srcRectUnscaled.top;
srcRectUnscaled.top = bottom;
- 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 ?
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?