This topic is now archived and is closed to further replies.


BitBlt() equivalent in Gdi+ ?

Recommended Posts

I''m trying to create an offscreen bitmap then paint it with yellow color then draw a red triangle on top of the yellow background then copy it onto visible screen. I get no errors but nothing is drawn. Take a look at the code below.
case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			HDC hOffscreenDC = CreateCompatibleDC(NULL);
			Graphics *Gfx = new Graphics(hOffscreenDC);

			Graphics *Gfx2 = new Graphics(hdc);

			Bitmap OffscreenSurface(200, 200, Gfx);

			ImageAttributes ImgAtr;
			ImgAtr.SetColorKey(Color::Black, Color::Black, ColorAdjustTypeBitmap);
			SolidBrush BkBrush(Color::Yellow);
			// Draw a red triangle (transparent bkgnd) onto yellow background in offscreen surface

			Status Rv = Gfx->FillRectangle(&BkBrush, 0, 0, OffscreenSurface.GetWidth(),
			assert(Ok == Rv);
			Rv = Gfx->DrawImage(&Bmp, Rect(20, 20, Bmp.GetWidth(), Bmp.GetHeight()),
				0, 0, Bmp.GetWidth(), Bmp.GetHeight(), UnitPixel, &ImgAtr);
			assert(Ok == Rv);

			// Draw the offscreen surface onto visible screen

			Rv = Gfx2->DrawImage(&OffscreenSurface, 0, 0);
			assert(Ok == Rv);

			delete Gfx;
			delete Gfx2;
			EndPaint(hWnd, &ps);
Thanks for any info

Share this post

Link to post
Share on other sites
Ok, I''ve figured out double buffering. Simply use Bitmap::Bitmap(width, height, format) constructor. Format member is weird because by default it will create 32bit argb bitmap even if my screen format is 16bpp. Maybe a conversion from 32bit to 16bit is happening, I don''t know. Another weird thing is that gdi+ stack based objects like Bitmap and Brush cause memory leaks but when created on heap they''re fine. Graphics object is fine as stack based only when taking in hdc but fails when image is passed to its constructor. So something funky is going on Am using win98 with gdi+ version 1.0 I think.

Share this post

Link to post
Share on other sites
I've put all my gdi+ objects onto the heap and no more memory leaks This probably stems from C# since everything is newed there like in Java. Wonder if stack based objects in C# would also bomb or not?

Edited by - JD on November 14, 2001 4:30:02 AM

Share this post

Link to post
Share on other sites
No bugs in gdi+ just my misunderstanding Two things:

1)Make sure all your gdi+ objects go out of scope when placed on stack before calling gdi+ shutdown function.

2)If you defined WIN32_LEAN_AND_MEAN before including windows.h header file you must include also ole2.h file. If you don''t define WIN32_LEAN_AND_MEAN then including windows.h will be
sufficient for gdi+ to compile. This when writing to win32 not mfc apps. Mfc includes ole2.h automatically I presume.

Share this post

Link to post
Share on other sites