Re: Get RGB Color of CBitmap at (x,y)
There are two ways, the easiest is to select the bitmap in a dc and then
call GetPixel. But that is slow.
The other way is to get the DIBits for the bitmap and then go through the
bitmap bits yourself. Here is an example, of course you would want to call
GetDIBits once to get bits and do all your look ups and then free the bits
array (this function is just to demonstrate how to do it).
DWORD GetColorXY(HDC hDC,HBITMAP hBitmap,int Width,int Height,int X, int Y)
{
BITMAPINFO lpInfo;
BYTE *lpBits;
lpBits=(BYTE *)malloc(Width*Height*sizeof(DWORD));
if(lpBits==NULL)
return -1;
memset(&lpInfo,0,sizeof(BITMAPINFO));
lpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpInfo.bmiHeader.biWidth = Width;
lpInfo.bmiHeader.biHeight = -Height;
lpInfo.bmiHeader.biPlanes = 1;
lpInfo.bmiHeader.biBitCount = 24;
lpInfo.bmiHeader.biCompression = BI_RGB;
lpInfo.bmiHeader.biSizeImage=0;
COLORREF Color = 0;
int Ret = GetDIBits(hDC, hBitmap, 0, Height, lpBits, &lpInfo,
DIB_RGB_COLORS);
if(Ret)
{
int i = x * 3 + (y * (Width * 3)) + (y * (Width%4));
Color = RGB(lpBits[i],lpBits[i+1],lpBits[i+2]);
}
free(lpBits);
return Color;
}
AliR.
"Matthias Pospiech" <matthiaspospiech@arcor.de> wrote in message
news:462e66de$0$6411$9b4e6d93@newsspool2.arcor-online.net...
I have an CBitmap as the result of loading a bmp file.
From this CBitmap I need to extract the color information to store that in
a seperate self defined array.
How can this be done ?
Matthias