Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am performing some basic drawing operation using gdi+ like drawing line ,circle ,rectangle etc..


C++
PAINTSTRUCT ps;
HDC         hdc;
hdc = ::BeginPaint(hWnd, &ps);
    graphics.DrawEllipse(&pen, x_start,y_start,x_current,y_current);
    EndPaint(g_hDialogWindow, &ps);



now i want to create HBITMAP of this drawn shape of size (640,480) with white background.
Posted
Comments
Nelek 16-Mar-12 15:26pm    
And where are you having problems? You made no question

Do you mean "How To Draw on a Memory Bitmap in GDI+"[^] (you may then use the Bitmap.GetHBITMAP[^] to retrieve the HBITMAP).
 
Share this answer
 
C++
HBITMAP dcimage;
Bitmap b(800,800);
HDC hdc;
hdc = BeginPaint(g_hDialogWindow, &ps);
Graphics graphics(g_hDialogWindow);
Graphics *graphics2=Graphics::FromImage(&b);

Pen  pen(Color(255, 40,40,40),2);
SolidBrush brush(Color::White);

graphics.FillRectangle(&brush, 0, 0, 400,400);
graphics2->FillRectangle(&brush, 0, 0, 400,400);
graphics.DrawLine(&pen,0,0,600,600);
graphics2->DrawLine(&pen,0,0,400,400);
b.GetHBITMAP(Color(255,255,255),&dcimage);



 BITMAP bm;
 HDC hdcMem = CreateCompatibleDC(hdc);
 SelectObject(hdcMem, dcimage);
 GetObject(dcimage, sizeof(bm), &bm);

 BitBlt(hdc,rect.left, rect.top, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
 DeleteDC(hdcMem);

 EndPaint(g_hDialogWindow, &ps);

thanks guys... :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900