BitBlt() equivalent in Gdi+ ?

Started by
2 comments, last by JD 22 years, 5 months ago
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);
			assert(hOffscreenDC);
									
			Graphics *Gfx = new Graphics(hOffscreenDC);
			assert(Gfx);

			Graphics *Gfx2 = new Graphics(hdc);
			assert(Gfx2);

			Bitmap OffscreenSurface(200, 200, Gfx);

			ImageAttributes ImgAtr;
			
			ImgAtr.SetColorKey(Color::Black, Color::Black, ColorAdjustTypeBitmap);
			
			Bitmap Bmp(GetModuleHandle(NULL), (WCHAR*)MAKEINTRESOURCE(IDB_TRIANGLE));			
			
			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(),
				OffscreenSurface.GetHeight());
			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;
			DeleteDC(hOffscreenDC);
						
			EndPaint(hWnd, &ps);
		}
		break;
  
Thanks for any info
Advertisement
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.
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
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.

This topic is closed to new replies.

Advertisement