一般处理BMP透明色有以下两种方法:
for( int x=0; x<=bmpWidth; x++)
{
for( int y=0; y<=bmpHeight; y++)
{
col = memDC.GetPixel(x, y);
if(col == colMask)
{
rgnTemp.CreateRectRgn(x, y, x+1, y+1);
wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);
rgnTemp.DeleteObject();
}
}
}
或者:HBITMAP hbmMask = (HBITMAP)CreateBitmap(srcWidth, srcHeight, 1, 1, NULL);
HDC hdcMask = CreateCompatibleDC(pDC->GetSafeHdc());
HBITMAP ohbmMask = (HBITMAP)SelectObject(hdcMask,hbmMask);
COLORREF ocrlBack = SetBkColor(hdcBits,RGB(255,255,255));
StretchBlt(hdcMask,0, 0, srcWidth, srcHeight, hdcBits, 0, 0,srcWidth,srcHeight, SRCCOPY);
StretchBlt(pDC->GetSafeHdc(),dstPosX,dstPosY,dstWidth, dstHeight, hdcBits, 0, 0,srcWidth,srcHeight, SRCINVERT);
StretchBlt(pDC->GetSafeHdc(),dstPosX,dstPosY,dstWidth, dstHeight, hdcMask, 0, 0,srcWidth,srcHeight, SRCAND);
StretchBlt(pDC->GetSafeHdc(),dstPosX,dstPosY,dstWidth, dstHeight, hdcBits, 0, 0,srcWidth,srcHeight, SRCINVERT);让我们来测试一下:
做一个BMP,里面画几个矩形框,分别填充RGB(255,255,255),RGB(254,254,254),RGB(253,253,253),RGB(252,252,252),
RGB(251,251,251),RGB(250,250,250)颜色。
当你用上面的方法调用时,你发现前四个矩形都透明了,后两个矩形不透明。
而理想的结果应该是只有RGB(255,255,255)应该透明。
请高手指教,为什么?如何才能让只有RGB(255,255,255)才透明。BMP透明显示的第二中方法,我是从http://www.codeguru.com/bitmap/CISBitmap.shtml
拿来的,所以不要怀疑代码的正确性。
for( int x=0; x<=bmpWidth; x++)
{
for( int y=0; y<=bmpHeight; y++)
{
col = memDC.GetPixel(x, y);
if(col == colMask)
{
rgnTemp.CreateRectRgn(x, y, x+1, y+1);
wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);
rgnTemp.DeleteObject();
}
}
}
或者:HBITMAP hbmMask = (HBITMAP)CreateBitmap(srcWidth, srcHeight, 1, 1, NULL);
HDC hdcMask = CreateCompatibleDC(pDC->GetSafeHdc());
HBITMAP ohbmMask = (HBITMAP)SelectObject(hdcMask,hbmMask);
COLORREF ocrlBack = SetBkColor(hdcBits,RGB(255,255,255));
StretchBlt(hdcMask,0, 0, srcWidth, srcHeight, hdcBits, 0, 0,srcWidth,srcHeight, SRCCOPY);
StretchBlt(pDC->GetSafeHdc(),dstPosX,dstPosY,dstWidth, dstHeight, hdcBits, 0, 0,srcWidth,srcHeight, SRCINVERT);
StretchBlt(pDC->GetSafeHdc(),dstPosX,dstPosY,dstWidth, dstHeight, hdcMask, 0, 0,srcWidth,srcHeight, SRCAND);
StretchBlt(pDC->GetSafeHdc(),dstPosX,dstPosY,dstWidth, dstHeight, hdcBits, 0, 0,srcWidth,srcHeight, SRCINVERT);让我们来测试一下:
做一个BMP,里面画几个矩形框,分别填充RGB(255,255,255),RGB(254,254,254),RGB(253,253,253),RGB(252,252,252),
RGB(251,251,251),RGB(250,250,250)颜色。
当你用上面的方法调用时,你发现前四个矩形都透明了,后两个矩形不透明。
而理想的结果应该是只有RGB(255,255,255)应该透明。
请高手指教,为什么?如何才能让只有RGB(255,255,255)才透明。BMP透明显示的第二中方法,我是从http://www.codeguru.com/bitmap/CISBitmap.shtml
拿来的,所以不要怀疑代码的正确性。
显卡保存颜色是16位的,分为555,和565格式,他们都是将颜色分量的最后3位去掉,(565格式的绿色分量去掉2位),所以
RGB(255,255,255),RGB(254,254,254),RGB(253,253,253),RGB(252,252,252)
这四个颜色,在显卡中颜色是一样的。
to:baixc 显卡问题吗?我在公司几个同事的机器上,得到的结果都是错误的。
真不到该怎么解决了?该死的StretchBlt!如何解决,谁知道?