MFC--位图

如何显示位图?

[cpp] view plain copy print ?
  1. CDC Dc;  
  2.     if(Dc.CreateCompatibleDC(pDC)==FALSE)  
  3.     AfxMessageBox("Can't create DC");  
  4.     Dc.SelectObject(&m_bitmap);  
  5.     pDC->BitBlt(10,10,500,500,&Dc,200,100,SRCCOPY);  
  6.   
  7. -----------------------另一种方式  
  8.   
  9. 直接加载外部 bmp, ico, cur    
  10.   
  11. CXXX::OnPaint()   
  12. {   
  13. CPaintDC dc(this);   
  14.   
  15. CDC  dcMem;   
  16. CBitmap  Bitmap ;   
  17. HBITMAP hBitmap ;   
  18. CRect rect ;   
  19.   
  20. GetClientRect( &rect ) ;   
  21. // 加载外部文件    
  22. hBitmap = (HBITMAP)::LoadImage(0, _T("D:\\test.bmp"), IMAGE_BITMAP, 0, 0   
  23. , LR_LOADFROMFILE);   
  24. if ( hBitmap == NULL )   
  25.     return ;   
  26.   
  27. Bitmap.Attach( hBitmap );   
  28.   
  29. // 把位图选入内存描述表    
  30. dcMem.CreateCompatibleDC( &dc ) ;   
  31. dcMem.SelectObject( & Bitmap );   
  32.   
  33. // 显示位图    
  34. // dcMem    
  35. dc.BitBlt( 0, 0, rect.Width(), rect.Height(), &dcMem, 0, 0, SRCCOPY );   
  36.   
  37. }   

显示RGB数据

CPaintDC dc(this); 
ConvertRGB24RToRGB24(g_pImageSrc,g_sRGB,m_nPicWidth,m_nPicHeight);  //倒转
DWORD dwBmpHdr = sizeof(BITMAPINFO);
BITMAPINFO m_bmphdr;
m_bmphdr.bmiHeader.biBitCount = 24;
m_bmphdr.bmiHeader.biClrImportant = 0;
m_bmphdr.bmiHeader.biSize = dwBmpHdr;
m_bmphdr.bmiHeader.biSizeImage = 0;
m_bmphdr.bmiHeader.biWidth = m_nPicWidth;
m_bmphdr.bmiHeader.biHeight = m_nPicHeight;
m_bmphdr.bmiHeader.biXPelsPerMeter = 0;
m_bmphdr.bmiHeader.biYPelsPerMeter = 0;
m_bmphdr.bmiHeader.biClrUsed = 0;
m_bmphdr.bmiHeader.biPlanes = 1;
m_bmphdr.bmiHeader.biCompression = BI_RGB;
int nResult = ::StretchDIBits(dc.m_hDC,0,0,m_nPicWidth,m_nPicHeight, 0, 0,m_nPicWidth, m_nPicHeight,g_sRGB,
			(BITMAPINFO*)&m_bmphdr,DIB_RGB_COLORS, SRCCOPY);


 

 

 

你可能感兴趣的:(MFC--位图)