1 DrawImage(const LPBYTE & lpdibBits, const CDC* pDC)
2 {
//int bmInfoSize = BMI_HDSIZE + colorTableSize;
//lpdibBits =new BYTE[bmInfoSize + bminfoheader.biSizeImage]; 即BITMAPINFO 的大小加上 位图像素值的大小
3 CImageDoc* pdoc = (CImageDoc*)GetDocument();
4 ASSERT_VALID(pdoc);
5 CDib* viewDib = pdoc->m_pDib;
6 if(viewDib->bmbits == NULL)
7 return ;
8
9 LPBYTE lpSourceBits;
10 LPBITMAPINFO lpBInfo= viewDib->pBmInfo;
11 HBITMAP hbitmap, hOldSourceBitmap;
12 HDC hCompatibleDc, hPicDc= pDC->GetSafeHdc();
13 int ImageWidth = viewDib->bminfoheader.biWidth ,
14 ImageHeight = viewDib->bminfoheader.biHeight;
15
16 hbitmap = CreateDIBSection(hPicDc,lpBInfo,DIB_RGB_COLORS,(void **)&lpSourceBits,NULL, 0);
17 hCompatibleDc = CreateCompatibleDC(hPicDc);
18 CopyMemory(lpSourceBits,lpdibBits+BMI_HDSIZE,viewDib->bminfoheader.biSizeImage);
19 hOldSourceBitmap = (HBITMAP)SelectObject( hCompatibleDc, hbitmap );
20
21 ::StretchBlt(hPicDc,0,0,ImageWidth,ImageHeight,hCompatibleDc,0,0,ImageWidth,ImageHeight,SRCCOPY);
22 SelectObject( hCompatibleDc, hOldSourceBitmap );
23 DeleteDC( hCompatibleDc );
24 GdiFlush();
25 }