怎么样获得句柄HBITMAP的位图数据流信息;代码如下:CRect Rect;
::GetWindowRect(hwnd,Rect);
HDC hSourceDC = ::GetDC(hwnd);
HDC hdc = ::CreateCompatibleDC(hSourceDC);HBITMAP hCaptureBitmap = ::CreateCompatibleBitmap(hSourceDC, Rect.Width(), Rect.Height());
::BitBlt(hdc,0,0,Rect.Width(),Rect.Height(),hSourceDC,0,0,SRCCOPY); 怎么样获得hCaptureBitmap的位图数据流呢
我采用
BITMAP bm;
::GetObject(hCaptureBitmap,sizeof(bm),(LPVOID)&bm);
可是bm的bmBits为NULL
各位有什么办法嘛
::GetWindowRect(hwnd,Rect);
HDC hSourceDC = ::GetDC(hwnd);
HDC hdc = ::CreateCompatibleDC(hSourceDC);HBITMAP hCaptureBitmap = ::CreateCompatibleBitmap(hSourceDC, Rect.Width(), Rect.Height());
::BitBlt(hdc,0,0,Rect.Width(),Rect.Height(),hSourceDC,0,0,SRCCOPY); 怎么样获得hCaptureBitmap的位图数据流呢
我采用
BITMAP bm;
::GetObject(hCaptureBitmap,sizeof(bm),(LPVOID)&bm);
可是bm的bmBits为NULL
各位有什么办法嘛
HGDIOBJ hgdiobj, // handle to graphics object
int cbBuffer, // size of buffer for object information
LPVOID lpvObject // buffer for object information
);
If hgdiobj is a handle to a bitmap created by calling CreateDIBSection, and the specified buffer is large enough, the GetObject function returns a DIBSECTION structure. In addition, the bmBits member of the BITMAP structure contained within the DIBSECTION will contain a pointer to the bitmap's bit values. If hgdiobj is a handle to a bitmap created by any other means, GetObject returns only the width, height, and color format information of the bitmap. You can obtain the bitmap's bit values by calling the GetDIBits or GetBitmapBits function.
http://community.csdn.net/Expert/topic/4614/4614713.xml?temp=9.312075E-02
希望能帮到你!
{
FILE * fp= NULL;
fp = fopen(szPath.GetBuffer(1),"wb");
if(fp == NULL)
return false;
BITMAP Bm;
BITMAPINFO BitInfo;
ZeroMemory(&BitInfo, sizeof(BITMAPINFO));
BitInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitInfo.bmiHeader.biBitCount = 0; if(!::GetDIBits(hDC, hBitmap, 0, 0, NULL, &BitInfo, DIB_RGB_COLORS))
return (false); Bm.bmHeight = BitInfo.bmiHeader.biHeight;
Bm.bmWidth = BitInfo.bmiHeader.biWidth; BITMAPFILEHEADER BmHdr;
BmHdr.bfType = 0x4d42; // 'BM' WINDOWS_BITMAP_SIGNATURE
BmHdr.bfSize = (((3 * Bm.bmWidth + 3) & ~3) * Bm.bmHeight)
+ sizeof(BITMAPFILEHEADER)
+ sizeof(BITMAPINFOHEADER);
BmHdr.bfReserved1 = BmHdr.bfReserved2 = 0;
BmHdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER)
+ sizeof(BITMAPINFOHEADER);
BitInfo.bmiHeader.biCompression = 0;
// Writing Bitmap File Header ////
fwrite(&BmHdr,sizeof(BITMAPFILEHEADER),1,fp); fwrite(&BitInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp); BYTE *pData = new BYTE[BitInfo.bmiHeader.biSizeImage + 5];
if(!::GetDIBits(hDC, hBitmap, 0, Bm.bmHeight,
pData, &BitInfo, DIB_RGB_COLORS))
return (false);
if(pData != NULL)
fwrite(pData,1,BitInfo.bmiHeader.biSizeImage,fp); fclose(fp);
delete (pData); return (true);
}
CFileDialog dlg(true,_T("BMP"),_T("bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.*|*.*|")); if (dlg.DoModal()!=IDOK)
return;
CString ss=dlg.GetPathName();
//m_bmp.LoadBitmap(ss);
hBmp=(HBITMAP)LoadImage(AfxGetInstanceHandle(),ss,
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
CBitmap *pBmp=CBitmap::FromHandle(hBmp);
BITMAP bm;
::GetObject(hBmp,sizeof(bm),(LPVOID)&bm);
m_bmWidth=bm.bmWidth;
m_bmHeight=bm.bmHeight;