19,469
社区成员
发帖
与我相关
我的任务
分享
typedef struct tagRGBX
{
public:
tagRGBX()
{
btRed = btBlue = btGreen = btUnused = 0;
}
tagRGBX(BYTE red, BYTE green, BYTE blue)
{
btRed = red;
btBlue = blue;
btGreen = green;
btUnused = 0;
}
tagRGBX(COLORREF color)
{
btRed = GetRValue(color);
btBlue = GetBValue(color);
btGreen = GetGValue(color);
btUnused = 0;
}
BYTE btBlue;
BYTE btGreen;
BYTE btRed;
protected:
BYTE btUnused;
public:
tagRGBX Gray()
{
int r = (int)btRed * 3;
int g = (int)btGreen * 6;
int b = (int)btBlue;
BYTE btGray = (BYTE)((r + g + b) / 10);
return RGBX(btGray, btGray, btGray);
}
}RGBX;
// 获取图像像素数据
RGBX* 你的CBitmap派生类::GetDIBits32()
{
BITMAPINFO bi;
int nHeight = PrepareBitmapInfo32(bi);
if (!nHeight)
return FALSE;
BYTE* pBits = (BYTE*)new BYTE[bi.bmiHeader.biSizeImage];
HDC hdc = GetDC(NULL);
if (!GetDIBits(hdc, (HBITMAP)GetSafeHandle(), 0, nHeight, pBits, &bi, DIB_RGB_COLORS))
{
delete pBits;
pBits = NULL;
}
::ReleaseDC(NULL, hdc);
return (RGBX*)pBits;
}