本文介绍了从gdi创建HBITMAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用gdi +执行一些基本的绘制操作,例如绘制线,圆,矩形等.
I am performing some basic drawing operation using gdi+ like drawing line ,circle ,rectangle etc..
PAINTSTRUCT ps;
HDC hdc;
hdc = ::BeginPaint(hWnd, &ps);
graphics.DrawEllipse(&pen, x_start,y_start,x_current,y_current);
EndPaint(g_hDialogWindow, &ps);
现在,我想用白色背景创建大小为(640,480)的此绘制形状的HBITMAP.
now i want to create HBITMAP of this drawn shape of size (640,480) with white background.
推荐答案
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... :)
这篇关于从gdi创建HBITMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!