在不同位置同時顯示兩張點陣圖
阿新 • • 發佈:2019-01-31
在OnDraw(CDC* pDC) 函式裡新增如下程式碼:
void CSDIFormView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
//
CBitmap bmp1,bmp2;
bmp1.LoadBitmap(IDB_BITMAP1);
bmp2.LoadBitmap(IDB_BITMAP2);
//
BITMAP bmpInfo1,bmpInfo2;
bmp1.GetBitmap(&bmpInfo1);
bmp2.GetBitmap(&bmpInfo2);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp1);
//顯示第一張圖片的一半
pDC-> BitBlt(0, 0, bmpInfo1.bmWidth/2, bmpInfo1.bmHeight/2, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
pOldBitmap = dcMemory.SelectObject(&bmp2);
//顯示第二張圖片的一半
pDC-> BitBlt(300, 300, bmpInfo2.bmWidth/2, bmpInfo2.bmHeight/2, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
}
void CSDIFormView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
//
CBitmap bmp1,bmp2;
bmp1.LoadBitmap(IDB_BITMAP1);
bmp2.LoadBitmap(IDB_BITMAP2);
//
BITMAP bmpInfo1,bmpInfo2;
bmp1.GetBitmap(&bmpInfo1);
bmp2.GetBitmap(&bmpInfo2);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp1);
//顯示第一張圖片的一半
pDC-> BitBlt(0, 0, bmpInfo1.bmWidth/2, bmpInfo1.bmHeight/2, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
pOldBitmap = dcMemory.SelectObject(&bmp2);
//顯示第二張圖片的一半
pDC-> BitBlt(300, 300, bmpInfo2.bmWidth/2, bmpInfo2.bmHeight/2, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
}