Re: GDI+ Image sizing
- From: "Bogdan" <nobody@xxxxxxxxxx>
- Date: Wed, 27 Sep 2006 09:36:44 -0400
I'm not familiar with memDC but the process of double buffering in GDI+ is
similar to GDI where you use CreateCompatibleDC/CreateCompatibleBitmap.
In GDI+ you create an offscreen (compatible) bitmap using a graphics object
created based on your view. Example:
Graphics graphics(GetSafeHwnd())
Bitmap* pbmp = new Bitmap(cx, cy, &graphics)
You can then create your offscreen graphics object as follows:
Graphics* pg = Graphics::FromImage(pbmp);
"Mark F." <replytogroup@xxxxxxxx> wrote in message
news:BxlSg.526$DU3.175@xxxxxxxxxxxxxxxxxxxxxxx
"Bogdan" <nobody@xxxxxxxxxx> wrote in message
news:ug8vW0d4GHA.3404@xxxxxxxxxxxxxxxxxxxxxxx
Few things that you might take into account:offscreen
1) Use double buffering to avoid ugly flashing. I.e. create an
bitmap, create an offscreen graphics using the offscreen bitmap, loadthe
image to another bitmap, use the offscreen graphics to draw the loadedto
bitmap to the offscreen bitmap, and then draw to the offscreen bitmap
screen (i.e. in your OnDraw()). You should also take into accountclipping
region to avoid drawing of the whole image.
Like a MemDC that you manipulate then draw. ?
2) No need to release HDC (at least not in your example). Whengraphics
object goes out of scope it'll cleanup after itself.
Ok.
3) And finally, answer to your question...source
In order to scale the image you need to use DrawImage that takes both
and destination rectangles. In order to avoid cropping make sure thatthe
source rectangle matches image's size.
The code should look something like the following:
graphics.DrawImage(&image, destRect, x, y, cx, cy, UnitPixel)
(x = 0, y = 0, cx = image width, cy = image height)
One of the overloaded functions for DrawImage.
Thanks!
.
- Follow-Ups:
- Re: GDI+ Image sizing
- From: Mark F.
- Re: GDI+ Image sizing
- References:
- GDI+ Image sizing
- From: Mark F.
- Re: GDI+ Image sizing
- From: Bogdan
- Re: GDI+ Image sizing
- From: Mark F.
- GDI+ Image sizing
- Prev by Date: Re: Events and messages and two different classes
- Next by Date: Floppy disk drives
- Previous by thread: Re: GDI+ Image sizing
- Next by thread: Re: GDI+ Image sizing
- Index(es):
Relevant Pages
|