15,979
社区成员
发帖
与我相关
我的任务
分享
void CMappingView::OnDraw(CDC* pDC)
{
/// 获取当前窗体矩形
CRect rect;
GetClientRect(rect);
/// 首先定义一个显示设备对象
CDC MemDC;
MemDC.CreateCompatibleDC(NULL);
/// 定义一个位图对象
CBitmap MemBitmap;
/// 创建位图大小
MemBitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
CBitmap *pOldBit = MemDC.SelectObject(&MemBitmap);
/// 画XY轴坐标
DrawCoordinate(&MemDC);
/// 将内存中的图像拷贝到显存中
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDC, rect.left, rect.top, SRCCOPY);
/// 画XY轴背景图
DrawCameraImage(pDC, &MemDC);
/// 画定位点位
DrawVisualization(&MemDC);
//pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDC, rect.left, rect.top, SRCCOPY);
/// 清空内存
MemDC.SelectObject(pOldBit);
MemBitmap.DeleteObject();
MemDC.DeleteDC();
}
void CMappingView::DrawCameraImage(CDC *pDC, CDC *memDC)
{
CMainFrame *p = (CMainFrame*)AfxGetMainWnd();
CMappingDoc *pDoc = (CMappingDoc*)GetDocument();
HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
"C:\\Windows\\Image_0619140611.bmp",
IMAGE_BITMAP,
0,0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION );
if(hbm == NULL)
{
return;
}
CBitmap* pBitmap = CBitmap::FromHandle(hbm);
BITMAP bmpInfo;
pBitmap->GetBitmap(&bmpInfo);
CBitmap *pOldBitmap = pDC->SelectObject(pBitmap);
memDC->SelectObject(pBitmap);
CRect rect;
GetClientRect(rect);
raxis.left = rect.left + 60;
raxis.right = rect.right - 20;
raxis.top = rect.top + 20;
raxis.bottom = rect.bottom - 60;
int width = raxis.right - raxis.left + 1;
width = width % 4 ? (width + (4 - width % 4)) : width;
raxis.right = raxis.left + width - 1;
pDC->StretchBlt(
r.left,
r.top,
r.Width(),
r.Height(),
memDC,
0,0,
bmpInfo.bmWidth,
bmpInfo.bmHeight,
SRCCOPY);
pBitmap->DeleteObject();
}