如何在MFC中绘制Alpha Blended位图? [英] How to draw Alpha Blended bitmap in MFC?
本文介绍了如何在MFC中绘制Alpha Blended位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都有Alpha Blended位图图像绘制的例子吗?
提前谢谢。
Any one have the example for Alpha Blended bitmap image drawing?
Thanks in advance.
推荐答案
要绘制以DIB(设备独立位图)提供的位图,必须将其转换为设备(通常为:屏幕)兼容的DDB(设备相关位图)。这可以使用 CreateDIBitmap() [ ^ ] GDI功能:
To draw a bitmap that is provided as DIB (Device Independant Bitmap), it must be converted to a device (usually: screen) compatible DDB (Device Dependant Bitmap). This can be done using the CreateDIBitmap()[^] GDI function:
// LPCVOID lpData points to a DIB
LPBITMAPINFOHEADER lpBIH = static_cast<LPBITMAPINFOHEADER>(lpData);
unsigned nColorSize = lpBIH->biClrUsed * sizeof(RGBQUAD);
if (lpBIH->biBitCount <= 8)
{
// If lpBIH->bmiHeader.biClrUsed is non zero it specifies the number of colors.
// If it is zero, all colors are used.
if (0 == nColorSize)
nColorSize = (lpBIH->biBitCount << 1) * sizeof(RGBQUAD);
}
// With BI_BITFIELDS compression, use 3 DWORDs.
else if (BI_BITFIELDS == lpBIH->biCompression)
nColorSize = 3 * sizeof(DWORD);
// Create a BITMAPINFO structure.
LPBYTE lpBiBuf[sizeof(BITMAPINFO) + 255 * sizeof(RGBQUAD)];
LPBITMAPINFO = lpBI reinterpret_cast<LPBITMAPINFO>(lpBiBuf);
// Copy the common content with V4 and V5 headers
::CopyMemory(lpBI, lpBIH, sizeof(BITMAPINFO));
// Adjust the size member
lpBI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// Copy the color table
if (nColorSize)
::CopyMemory(lpBI->bmiColors, static_cast<LPBYTE>(lpData) + lpBIH->biSize, nColorSize);
HDC hScreen = ::GetDC(NULL);
HBITMAP hBitmap = ::CreateDIBitmap(
hScreen, // Create screen compatible bitmap
lpBIH, // BITMAPINFOHEADER, BITMAPV4HEADER, or BITMAPV5HEADER
CBM_INIT, // Initialize bitmap with data from next parameters
static_cast<LPBYTE>(lpData) + lpBIH->biSize + nColorSize,
lpBI, // BITMAPINFO (BITMAPINFOHEADER followed by color table)
DIB_RGB_COLORS); // Color table uses RGB values
::ReleaseDC(NULL, hScreen);
现在可以将创建的位图选择到设备上下文中,并使用其中一个阻塞函数绘制。
The created bitmap can be now be selected into a device context and drawn using one of the blitter functions.
这篇关于如何在MFC中绘制Alpha Blended位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文