Re: GDI+ Image sizing

Tech-Archive recommends: Fix windows errors by optimizing your registry



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:

1) Use double buffering to avoid ugly flashing. I.e. create an
offscreen
bitmap, create an offscreen graphics using the offscreen bitmap, load
the
image to another bitmap, use the offscreen graphics to draw the loaded
bitmap to the offscreen bitmap, and then draw to the offscreen bitmap
to
screen (i.e. in your OnDraw()). You should also take into account
clipping
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). When
graphics
object goes out of scope it'll cleanup after itself.


Ok.

3) And finally, answer to your question...
In order to scale the image you need to use DrawImage that takes both
source
and destination rectangles. In order to avoid cropping make sure that
the
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!





.



Relevant Pages

  • The story: Painting bitmap to screen is slow
    ... I've done a lot graphics programming by now and the thing that bothers me with GDI+ in .NET framework the most is slow drawing of bitmaps to screen. ... In Win32, there were two types of bitmaps, compatible and memory bitmap. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: The story: Painting bitmap to screen is slow
    ... The general "trick" behind great GDI+ performance is to do all drawing ... single bitmap to the screen. ... I heard Microsoft broke GDI acceleration for some operations in Vista. ... your configuration of Vista or graphics driver. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Double buffering with Metafiles
    ... > create a Graphics object from that hdc. ... > metafile from memory to the screen. ... > This is the same method for double buffering a bitmap. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: The story: Painting bitmap to screen is slow
    ... GDI bitmap pointing to the same area of memory. ... onto a Graphics device context. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: GDI+ very slow
    ... DrawImageUnscaled when using the correct bitmap format. ... because GDI uses hardware acceleration. ... For double buffering look for the ... but very fast when drawing on a back buffer (a memory ...
    (microsoft.public.dotnet.framework.drawing)