CRect rect(0,0,iLen,iLen); HBITMAP hBitmap = CopyScrToBitmap(rect); //该方法见 VC截取桌面到 bitmap //http://blog.pfan.cn/lym51/51672.html if (hBitmap!= NULL) { CBitmap* bitmap = CBitmap::FromHandle(hBitmap); BITMAP bmp; bitmap->GetBitmap(&bmp); int bitmapSize=bmp.bmWidthBytes*bmp.bmWidthBytes; BYTE* px = (BYTE*)GlobalAlloc(GPTR, bitmapSize); if (px==NULL) { return 0; } //bitmap->SetBitmapBits(bitmapSize, px); bitmap->GetBitmapBits(bitmapSize, px); int pixelBytes = bmp.bmBitsPixel/8; int x,y,index; int pos=0; for (y=0; y<bmp.bmHeight; ++y) { pos = 0; for (x=0; x<bmp.bmWidth; ++x) { index = y*bmp.bmWidthBytes + x*pixelBytes; px[index]; // B px[index+1]; // G px[index+2]; // R } } ::GlobalFree(px); bitmap->DeleteObject(); }

评论