用GetBitmapBits保存图片信息到数组中,每个点对应一个int,其中的r、g、b是怎么分配的?我使用时怎么总是颜色有偏差,好像遗漏了什么信息看看是哪里不对啊 GetBitmapBits(hbit,sizeof(int)*width*height,bmpbits);
for (i=0;i<width*height;i++)
{
j=*(bmpbits+i);
r = j & 255;
g = (j / 256) & 255;
b = (j / 65536) & 255;
//a = (j / 256/256) & 255;
r=255-r;
g=255-g;
b=255-b;
*(bmpbits+i)=RGB(r,g,b);
}
for (i=0;i<width*height;i++)
{
j=*(bmpbits+i);
r = j & 255;
g = (j / 256) & 255;
b = (j / 65536) & 255;
//a = (j / 256/256) & 255;
r=255-r;
g=255-g;
b=255-b;
*(bmpbits+i)=RGB(r,g,b);
}
解决方案 »
- 伪造IP地址,原始套接字sendto报10049错误
- 请问使用DAO或ADO连接,在不安装的ACCESS的机器上是否仍然可以访问!
- 请问如何在对话框启动时按自己输入的数目显示文本框
- ftp如何使下载文件的最后修改时间保持和服务器上源文件的时间一致
- 利用 gsoap 开发c++ webservice
- 有没有老得快退休的前辈,没有关门弟子的
- 请问除了西门子的TC35和MC35之外还有哪些厂家的哪些型号的手机模块,谢谢
- 在ScrollView中绘制的图形如何实现平滑卷动
- help!在SDI中切分窗口之后,想在view或doc中响应菜单项中的函数,请问怎么响应不了呢?
- 45分钟在线,下线结贴!请教在单文档中显示不同对话框,并和对话框类相连的各种方法!
- 想请教一下:关于打开CFileDialog类的使用问题》紧急!
- 有没有测试MODEM是否具有来电显示的功能的程序?
颜色有几位,是在bitmapinfoheader中看的吧。GetBitmapBits
The GetBitmapBits function copies the bitmap bits of a specified bitmap into a buffer. Note This function is provided only for compatibility with 16-bit versions of Windows. Win32-based applications should use the GetDIBits function. LONG GetBitmapBits(
HBITMAP hbmp, // handle to bitmap
LONG cbBuffer, // number of bytes to copy
LPVOID lpvBits // buffer to receive bits
);
Parameters
hbmp
[in] Handle to the bitmap of interest.
cbBuffer
[in] Specifies the number of bytes to copy from the bitmap into the buffer.
lpvBits
[out] Pointer to a buffer to receive the bitmap bits. The bits are stored as an array of byte values.
Return Values
If the function succeeds, the return value is the number of bytes copied to the buffer.If the function fails, the return value is zero. Windows NT/ 2000: To get extended error information, call GetLastError. Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
typedef struct tagBITMAP { /* bm */
int bmType;
int bmWidth;
int bmHeight;
int bmWidthBytes;
BYTE bmPlanes;
BYTE bmBitsPixel;
LPVOID bmBits;
} BITMAP;
如果你用的是DIB读取得话,那么你应该创建了逻辑调色板吧?这样的话,灰读图像R=G=B,彩色则是不等。你最好定义一个nBytesWidth,(宽度上的字节数)nBitsPiexl(每个想素点的位数),建议你看看微软madn上面的diblook吧。讲的比较仔细。
判断颜色的可以用一个messagebox讲这个数值显示出来,我记得有个函数可以得到位数的,我用过的,在madn上面查一下吧
lpBits = (BYTE*)HeapAlloc(GetProcessHeap(), 0, 80*120*nChannels);
GetBitmapBits(hBmp, 80*120*nChannels, lpBits);
IplImage* img = cvCreateImage(cvSize(80, 120), 8, nChannels);
memset(img->imageData, 0, 80*120*nChannels);
memcpy(img->imageData, (char*)lpBits, 80*120*nChannels);