1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| void CEnBitmap::DrawOnDC(CDC *pDC,CRect PicRect, bool bStretch/*=true*/, bool bTransparent/*=false*/)
{
CBitmap BigBmp;
CDC MemDcbb,MemDc;
MemDc.CreateCompatibleDC(NULL);
CBitmap *pOldBmp = MemDc.SelectObject(this);
if (!pOldBmp) return;
BITMAP BM;
GetObject(sizeof(BM), &BM); // Retrieve size of Bitmap
if (!bStretch)
{
PicRect.right = PicRect.left+BM.bmWidth;
PicRect.bottom = PicRect.top+BM.bmHeight;
}
// StretchBlt is not suppoted by all device
// Create a big Bitmap in memory, stretch the bitmap in this memory space
// and use BitBlt to print this new Big bitmap
//
BigBmp.CreateCompatibleBitmap(pDC,PicRect.Width(),PicRect.Height());
MemDcbb.CreateCompatibleDC(NULL);
MemDcbb.SelectObject(&BigBmp);
MemDcbb.StretchBlt(0,0,PicRect.Width(),PicRect.Height(),&MemDc,0,0,BM.bmWidth,BM.bmHeight, SRCCOPY);
COLORREF cBck = RGB(255,255,255);
if(bTransparent)
cBck = GetPixel(0,0);
pDC->TransparentBlt(PicRect.left,PicRect.top,PicRect.Width(),PicRect.Height(),&MemDcbb,0,0,PicRect.Width(),PicRect.Height(),cBck);
//else
//{
// //try{
// // pDC->BitBlt(PicRect.left,PicRect.top,PicRect.Width(),PicRect.Height(),&MemDcbb,0,0,SRCCOPY);
// //}
// //catch(...){};
//}
} |
Partager