打开一个图像文件之后,如何获得每个象素的RGB值或者灰度值并对其进行处理?(比如二值化或者计算灰度画灰度直方图等等)如果得到的是RGB的值如何转换成灰度值。新手,所以各位高人请讲的浅显一些。多谢了。

解决方案 »

  1.   

    RGB -> gray
    gray=(r*0.299+g*0.587+b*0.114);得到像素的值,你先看看书吧,关于图像格式讲的很详细。最简单的差不多是bmp位图,找一本图像编程的书看看吧,很简单的。
      

  2.   

    CDC::GetPixel  
    COLORREF GetPixel( int x, int y ) const;COLORREF GetPixel( POINT point ) const;Return ValueFor either version of the function, an RGB color value for the color of the given point. It is –1 if the coordinates do not specify a point in the clipping region.ParametersxSpecifies the logical x-coordinate of the point to be examined.ySpecifies the logical y-coordinate of the point to be examined.pointSpecifies the logical x- and y-coordinates of the point to be examined.
      

  3.   

    COLORREF clr=::GetPixel(m_hdc,x,y);
    CString ClrText;
    ClrText.Format("R值为:%d\nG值为:%d\nB值为:%d",(int)GetRValue(clr),(int)GetGValue(clr),(int)GetBValue(clr));
    ::MessageBox(NULL,ClrText,"输出的RGB值",MB_OK);