CreateDIBSection

#define BMPWIDTHBYTES(bytes) ((((bytes) + 31) >> 5) << 2) // bitmap 4 bytes assign = /32*4

BITMAP bmp;
  GetObject(hBmpMem,sizeof(BITMAP),&bmp);

  BITMAPINFO bmpInfo;
  ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
  bmpInfo.bmiColors[0].rgbRed = 0;
  bmpInfo.bmiColors[0].rgbBlue = 0;
  bmpInfo.bmiColors[0].rgbGreen = 0;
  bmpInfo.bmiColors[0].rgbReserved = 0;
  bmpInfo.bmiHeader.biBitCount = 24;
  bmpInfo.bmiHeader.biClrImportant = 0;
  bmpInfo.bmiHeader.biClrUsed = 0;
  bmpInfo.bmiHeader.biCompression = 0;
  bmpInfo.bmiHeader.biHeight =  - bmp.bmHeight;
  bmpInfo.bmiHeader.biPlanes = 1;
  bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);
  bmpInfo.bmiHeader.biSizeImage = BMPWIDTHBYTES( bmp.bmWidth * bmpInfo.bmiHeader.biBitCount) * bmp.bmHeight;
  bmpInfo.bmiHeader.biWidth = bmp.bmWidth;
  bmpInfo.bmiHeader.biXPelsPerMeter = 3780;
  bmpInfo.bmiHeader.biYPelsPerMeter = 3780;

  UCHAR   *pBuffer = NULL;  
  HDC hDcDib = CreateCompatibleDC(hDc);
  HBITMAP hDibBmp = CreateDIBSection(hDc,&bmpInfo,DIB_RGB_COLORS,(void**)&pBuffer,NULL,0);

SelectObject(hDcDib,hOldDibBmp);
  DeleteObject(hDibBmp);
::SelectObject(hDcDib,hOldDibBmp);
  DeleteObject(hDibBmp);
  DeleteDC(hDcDib);
  DeleteDC(hDcDib);

posted on 2009-03-16 08:50  Welkin Jiao  阅读(469)  评论(0)    收藏  举报

导航