VS2015用CxImage读入各种图片格式后在内存中转换为HBITMAP位图
VS2015用CxImage读入各种图片格式后在内存中转换为HBITMAP位图//将CxImage转为位图
HBITMAP Draw::ChangeCxImageToBMP(HDC hDC,CxImage* cximage)
{
//创建HBITMAP
HBITMAP BMP=CreateCompatibleBitmap(hDC,cximage->GetWidth(),cximage->GetHeight());
BITMAP bm;
GetObject(BMP,sizeof(BITMAP),&bm);
int pb=bm.bmBitsPixel/8; //获取位图位数
int BytesPerLineOut = (bm.bmWidth*pb + 3) / 4 * 4; //计算每行像素的数据长度
BYTE *pxd = new unsigned char; //声明暂存数组
if(cximage->GetBpp()>=16)
{
//直接获取像素数据
int pbx=cximage->GetBpp()/8; //获取CxImage图片的位数
int BytesPerLine = (bm.bmWidth*pbx + 3) / 4 * 4; //计算CxImage每行像素的数据长度
BYTE *pDib = cximage->GetBits(); //获取CxImage图片的像素数据
for (int i = 0; i < bm.bmHeight; i++)
{
for (int j = 0; j < bm.bmWidth; j++)
{
int srcRGB_B=(bm.bmHeight-1-i)*BytesPerLine+j*pbx;
int desRGB_B=i*bm.bmWidthBytes+j*pb;
pxd = pDib;
pxd = pDib;
pxd = pDib;
}
}
}
else
{
//通过调色板获取像素数据
for (int i = 0; i < bm.bmHeight; i++)
{
for (int j = 0; j < bm.bmWidth; j++)
{
RGBQUAD srcRGB_B=cximage->GetPixelColor(j,bm.bmHeight-1-i);
int desRGB_B=i*bm.bmWidthBytes+j*pb;
pxd = srcRGB_B.rgbBlue;
pxd = srcRGB_B.rgbGreen;
pxd = srcRGB_B.rgbRed;
}
}
}
SetBitmapBits(BMP,bm.bmHeight*bm.bmWidthBytes,pxd);
delete[] pxd;
return BMP;
}
页:
[1]