LONG WINAPI CountColor (HBITMAP hBmp,int x,int y,int width,int height)
file://COLORREF cOldColor,COLORREF cNewColor,)
{
LONG col=0;
char str[40];
HBITMAP RetBmp=NULL;
HBITMAP hhBmp=NULL;
if (hBmp)
{
HDC BufferDC=CreateCompatibleDC(NULL); // 源位图
if (BufferDC)
{
hhBmp=(HBITMAP)SelectObject(BufferDC,hBmp);//
HDC DirectDC=CreateCompatibleDC(NULL); // 目标DC
if (DirectDC)
// 获取源位图大小]f=CK
{
BITMAP bm;
GetObject(hhBmp, sizeof(bm), &bm);
// 初始化BITMAPINFO信息,以便使用CreateDIB
BITMAPINFO RGB32BitsBITMAPINFO;
ZeroMemory(&RGB32BitsBITMAPINFO,sizeof(BITMAPINFO));
RGB32BitsBITMAPINFO.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
RGB32BitsBITMAPINFO.bmiHeader.biWidth=bm.bmWidth;
RGB32BitsBITMAPINFO.bmiHeader.biHeight=bm.bmHeight;
RGB32BitsBITMAPINFO.bmiHeader.biPlanes=1;
RGB32BitsBITMAPINFO.bmiHeader.biBitCount=32;
UINT * ptPixels;
HBITMAP DirectBitmap= CreateDIBSection(DirectDC,(BITMAPINFO *)
&RGB32BitsBITMAPINFO,DIB_RGB_COLORS,(void **)&ptPixels, NULL, 0);
if (DirectBitmap)
{
HGDIOBJ PreviousObject=SelectObject(DirectDC, DirectBitmap);
BitBlt(DirectDC,0,0,width,height,BufferDC,x,y,SRCCOPY);
// 转换 COLORREF 为 RGBb54
// cOldColor=COLORREF2RGB(cOldColor);
// cNewColor=COLORREF2RGB(cNewColor);
// 替换颜色\O_
// sprintf(str,"%u",GetPixel(PreviousObject,10,10));
// MessageBox(0,str,"",0);
// sprintf(str,"%u",GetPixel(PreviousObject,80,40));
// MessageBox(0,str,"",0);
for (int i=((bm.bmWidth*bm.bmHeight)-1);i>=0;){
col=col+ptPixels[i];
// if (ptPixels[i]==cOldColor) ptPixels[i]=cNewColor;
i=i-1000;}
// for(int i=1;i<bm.bmWidth;){
// for(int m=1;m<bm.bmHeight;)
// {col=col+GetPixel(BufferDC,i,m);
// m=m+10;}
// i=i+10;}
// 修改位图 DirectBitmapx>6
SelectObject(DirectDC,PreviousObject);
// 完成w"Nq
// RetBmp=DirectBitmap;}
DeleteObject(PreviousObject);}
// 释放DC@
DeleteDC(DirectDC);
}
// DeleteObject(hhBmp);
// 释放DCe8tZ>q
DeleteDC(BufferDC);
}
}
file://return RetBmp;
return col;
}