MFC提取位图二进制信息的有关问题
MFC提取位图二进制信息的问题
我用下面的代码提取BITMAP的二进制像素,但是long sizeofdata = pBM.GetBitmapBits(bmptemp.bmWidth * bmptemp.bmHeight * imgSize, lpvBits);提取到的是空数组,希望大神们指教下!!
CDC* dcMem;
CBitmap pBM ;
unsigned char pData[500]="0";
pBM.LoadBitmap(IDB_BITMAP1);
BITMAP bmptemp = {0};
pBM.GetBitmap(&bmptemp);
BYTE imgSize = bmptemp.bmBitsPixel / 8;
BYTE* lpvBits = new BYTE[bmptemp.bmWidth * bmptemp.bmHeight * imgSize];
::ZeroMemory(lpvBits, bmptemp.bmWidth * bmptemp.bmHeight * imgSize);
long sizeofdata = pBM.GetBitmapBits(bmptemp.bmWidth * bmptemp.bmHeight * imgSize, lpvBits);//返回的是空数组
if(0 == sizeofdata)
{
delete [] lpvBits;
lpvBits = NULL;
}
int temp = 0;
BYTE buffer = 0;
for(int j = bmptemp.bmHeight - 1;j >= 0;j--)
{
for(int i = 0;i < bmptemp.bmWidth;i++)
{
buffer = lpvBits[(j * bmptemp.bmWidth + i) * imgSize];
memcpy(&pData[temp++], &buffer, 1);
}
}
if(lpvBits != 0)
{
delete [] lpvBits;
lpvBits = 0;
}
------解决方案--------------------
GetDIBits用这个函数试试
我用下面的代码提取BITMAP的二进制像素,但是long sizeofdata = pBM.GetBitmapBits(bmptemp.bmWidth * bmptemp.bmHeight * imgSize, lpvBits);提取到的是空数组,希望大神们指教下!!
CDC* dcMem;
CBitmap pBM ;
unsigned char pData[500]="0";
pBM.LoadBitmap(IDB_BITMAP1);
BITMAP bmptemp = {0};
pBM.GetBitmap(&bmptemp);
BYTE imgSize = bmptemp.bmBitsPixel / 8;
BYTE* lpvBits = new BYTE[bmptemp.bmWidth * bmptemp.bmHeight * imgSize];
::ZeroMemory(lpvBits, bmptemp.bmWidth * bmptemp.bmHeight * imgSize);
long sizeofdata = pBM.GetBitmapBits(bmptemp.bmWidth * bmptemp.bmHeight * imgSize, lpvBits);//返回的是空数组
if(0 == sizeofdata)
{
delete [] lpvBits;
lpvBits = NULL;
}
int temp = 0;
BYTE buffer = 0;
for(int j = bmptemp.bmHeight - 1;j >= 0;j--)
{
for(int i = 0;i < bmptemp.bmWidth;i++)
{
buffer = lpvBits[(j * bmptemp.bmWidth + i) * imgSize];
memcpy(&pData[temp++], &buffer, 1);
}
}
if(lpvBits != 0)
{
delete [] lpvBits;
lpvBits = 0;
}
------解决方案--------------------
GetDIBits用这个函数试试