• Advertisement
Sign in to follow this  

GDI+ draw to bitmap

This topic is 3895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having some trouble getting a basic application to work with GDI+. DrawImage(bitmapScreen) seems to do nothing, and I'm not sure why. A few rounds with the debugger tells me that all the code is supposedly running correctly, but nothing shows up when I call DrawImage(bitmapScreen). this is the code that makes changes to the offscreen bitmap:
LRESULT CALLBACK CPaintBox::OnMouseMove(HWND hWnd, int x, int y, UINT keyFlags)
	RECT rcClient = {0};
	GetClientRect(hWnd, &rcClient);

	int nx = x / (rcClient.right / sizeCanvas.Width), ny = y / (rcClient.bottom / sizeCanvas.Height);
	if(/*keyFlags & MK_LBUTTON && */bitmapScreen) {
		Graphics g(bitmapScreen);
		SolidBrush foreBrush(colorForeground);
		Rect rcFill(nx - 1, ny - 1, nx + 1, ny + 1);

		g.FillRectangle(&foreBrush, rcFill);

	return 0;
this is the code that draws the offscreen bitmap, onscreen:
if(bitmapScreen) {
		g.DrawImage(bitmapScreen, 0, 0, rcClient.right, rcClient.bottom);
	if(drawGrid) {
		Pen greyPen(Color(255, 192, 192, 192));
		for(int i = 0; i < sizeCanvas.Width; i++) {
			g.DrawLine(&greyPen, (i+1)*sizePixel.Width, 0, (i+1)*sizePixel.Width, rcClient.bottom);
			g.DrawLine(&greyPen, 0, (i+1)*sizePixel.Height, rcClient.right, (i+1)*sizePixel.Height);
the grid that is drawn inside the if(drawGrid) block seems to show up fine! ( and yes I did try moving my mouse a bit inside the window, :P ) thanks in advance!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement