如何得到BITMAP中bmBits对应的实际图像数据地址 用GetDibits函数将数据考出有点慢,我想直接对原内存中数据操作,但不知如何得到数据地址,最好不用mfc. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 只能够用GetDibits没有别的方法 看下面的代码:BITMAPINFO * BitmapToDIB(HPALETTE hPal, // palette for color conversion HBITMAP hBmp, // DDB for convert int nBitCount, int nCompression) // format wanted{ typedef struct { BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[256+3]; } DIBINFO; BITMAP ddbinfo; DIBINFO dibinfo; // retrieve DDB information if ( GetObject(hBmp, sizeof(BITMAP), & ddbinfo)==0 ) return NULL; // fill out BITMAPINFOHEADER based on size and required format memset(&dibinfo, 0, sizeof(dibinfo)); dibinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); dibinfo.bmiHeader.biWidth = ddbinfo.bmWidth; dibinfo.bmiHeader.biHeight = ddbinfo.bmHeight; dibinfo.bmiHeader.biPlanes = 1; dibinfo.bmiHeader.biBitCount = nBitCount; dibinfo.bmiHeader.biCompression = nCompression; HDC hDC = GetDC(NULL); // screen DC HGDIOBJ hpalOld; if ( hPal ) hpalOld = SelectPalette(hDC, hPal, FALSE); else hpalOld = NULL; // query GDI for image size GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, NULL, (BITMAPINFO *) & dibinfo, DIB_RGB_COLORS); int nInfoSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * GetDIBColorCount(dibinfo.bmiHeader); int nTotalSize = nInfoSize + GetDIBPixelSize(dibinfo.bmiHeader); BYTE * pDIB = new BYTE[nTotalSize]; if ( pDIB ) { memcpy(pDIB, & dibinfo, nInfoSize); if ( ddbinfo.bmHeight != GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, pDIB + nInfoSize, (BITMAPINFO *) pDIB, DIB_RGB_COLORS) ) { delete [] pDIB; pDIB = NULL; } } if ( hpalOld ) SelectObject(hDC, hpalOld); ReleaseDC(NULL, hDC); return (BITMAPINFO *) pDIB;} 还有几个函数int GetDIBPixelSize(const BITMAPINFOHEADER & bmih){ if ( bmih.biSizeImage ) return bmih.biSizeImage; else return ( bmih.biWidth * bmih.biBitCount + 31 ) / 32 * 4 * bmih.biPlanes * abs(bmih.biHeight);}int GetDIBColorCount(const BITMAPINFOHEADER & bmih){ if ( bmih.biBitCount <= 8 ) if ( bmih.biClrUsed ) return bmih.biClrUsed; else return 1 << bmih.biBitCount; else if ( bmih.biCompression==BI_BITFIELDS ) return 3 + bmih.biClrUsed; else return bmih.biClrUsed;} 高手看过来,如何加消息 如何提高文件写放效率? 关于SPI 如何控制分割视图 如何得到一个指向一对话框的指针 那位大虾帮忙? 托盘编程问题 mfc求助,如何实现属性页式的菜单(附图) 短信平台??? 两个VARIANT变量,都是BSTR型的,如何把它们相加连成一个VARIANT型的字符串? 高分相送!!!1000分!!关于繁体WIN98全拼输入法的安装!!!! 请问如何使CEditView 的内容清空?
HBITMAP hBmp, // DDB for convert
int nBitCount, int nCompression) // format wanted
{
typedef struct
{
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[256+3];
} DIBINFO; BITMAP ddbinfo;
DIBINFO dibinfo; // retrieve DDB information
if ( GetObject(hBmp, sizeof(BITMAP), & ddbinfo)==0 )
return NULL; // fill out BITMAPINFOHEADER based on size and required format
memset(&dibinfo, 0, sizeof(dibinfo)); dibinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
dibinfo.bmiHeader.biWidth = ddbinfo.bmWidth;
dibinfo.bmiHeader.biHeight = ddbinfo.bmHeight;
dibinfo.bmiHeader.biPlanes = 1;
dibinfo.bmiHeader.biBitCount = nBitCount;
dibinfo.bmiHeader.biCompression = nCompression; HDC hDC = GetDC(NULL); // screen DC
HGDIOBJ hpalOld;
if ( hPal )
hpalOld = SelectPalette(hDC, hPal, FALSE);
else
hpalOld = NULL; // query GDI for image size
GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, NULL, (BITMAPINFO *) & dibinfo, DIB_RGB_COLORS); int nInfoSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * GetDIBColorCount(dibinfo.bmiHeader);
int nTotalSize = nInfoSize + GetDIBPixelSize(dibinfo.bmiHeader); BYTE * pDIB = new BYTE[nTotalSize]; if ( pDIB )
{
memcpy(pDIB, & dibinfo, nInfoSize);
if ( ddbinfo.bmHeight != GetDIBits(hDC, hBmp, 0, ddbinfo.bmHeight, pDIB + nInfoSize, (BITMAPINFO *) pDIB, DIB_RGB_COLORS) )
{
delete [] pDIB;
pDIB = NULL;
}
} if ( hpalOld )
SelectObject(hDC, hpalOld); ReleaseDC(NULL, hDC); return (BITMAPINFO *) pDIB;
}
int GetDIBPixelSize(const BITMAPINFOHEADER & bmih)
{
if ( bmih.biSizeImage )
return bmih.biSizeImage;
else
return ( bmih.biWidth * bmih.biBitCount + 31 ) / 32 * 4 * bmih.biPlanes * abs(bmih.biHeight);
}int GetDIBColorCount(const BITMAPINFOHEADER & bmih)
{
if ( bmih.biBitCount <= 8 )
if ( bmih.biClrUsed )
return bmih.biClrUsed;
else
return 1 << bmih.biBitCount;
else if ( bmih.biCompression==BI_BITFIELDS )
return 3 + bmih.biClrUsed;
else
return bmih.biClrUsed;
}