void CLCLRView::writeimage()
2 {
3
4 LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_hDib);
5 int lineByte=(m_Width*m_BitCount/8+3)/4*4;
6 int imageSize =lineByte*m_Height;
7 int i,j;
11 CString str1;
12 ofstream outfile("C:/Users/Administrator/Desktop/图像像素.txt",ios::in|ios::trunc);
13 for(i=0;i<m_Height;i++)
14 {
15 for(j=0;j<m_Width;j++)
16 {
17 str1.Format("%d*%d*%d",*(lpDIB+i*lineByte+j*3+0),*(lpDIB+i*lineByte+j*3+1),*(lpDIB+i*lineByte+j*3+2));
20 outfile<<str1<<" ";
21 }
22 outfile<<endl;
23 }
24
25 ::GlobalUnlock((HGLOBAL) m_hDib);
26 }
各位高手这是我写的代码,m_hDib是DIB图像句柄,、lpDIB得到图像信息位,通过调用图像信息位查看,该BMP图像每一像素的RGB三原色值,但是奇怪的发现竟然有负数。请问这是什么原因啊?
问题二:VC++ 处理图像,必须将24色真彩图像转化为灰度图,建立灰度图得到灰度矩阵才可以进行之后的处理,是不是每一像素的灰度Y=0.299R+0.587G+0.114B ,通过计算每一点Y值得到图像灰度矩阵从而进行计算和处理???