问题描述
- 关于读取lena图像的灰度值到状态栏的问题
- 本人小白,最近看了点数字图像的书,为了便于图像的分析,希望把这幅图像的数据信息显示在状态栏上,但显示的时候却出了问题:我想让gray的值为该副图片的灰度值,可这个结果显然是不对的。先贴出在Mousemove消息下的代码如下,希望各位大神帮忙看下哪里出错了 ,感激不尽
void CImageProcessView::OnMouseMove(UINT nFlags CPoint point)
{CClientDC dc(this);
COLORREF gray=dc.GetPixel(point);
CString str;
str.Format(""x=%dy=%dgray=%d""point.xpoint.ygray);
((CMainFrame*) GetParent())->m_wndStatusBar.SetWindowText(str);}
解决方案
COLORREF RGB
(
BYTE byRed // red component of color
BYTE byGreen // green component of color
BYTE byBlue // blue component of color
);
COLORREF 是一个 32-bit 整型数值,它代表了一种颜色你直接转换肯定不对。
BYTE r = GetRValue(colorrrefRGB);
BYTE g = GetGValue(colorrrefRGB);
BYTE b = GetBValue(colorrrefRGB);
获取rgb值求平均。
时间: 2024-09-10 07:07:00