convert RGB color values into shades of gray with this formula:
r/g/b = (red * 0.30) + (green * 0.59) + (blue * 0.11) |
class CHexDoc:public CDocument
{
public:
CHexDoc();
DECLARE_DYNCREATE(CHexDoc)
public:
BYTE GetBytes(UINT nIndex,UINT nCode,PVOID nBuffer);
UINT GetDocumentLength();
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual void DeleteContents();
public:
virtual ~CHexDoc();
protected:
BYTE* m_pFileData;
UINT m_nDocLength;
DECLARE_MESSAGE_MAP()
};
class CHexView : public CScrollView
{
protected:
CHexView();
DECLARE_DYNCREATE(CHexView)
public:
CHexDoc* GetDocument();
public:
virtual void OnDraw(CDC* pDC);
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate();
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
public:
virtual ~CHexView();
protected:
void FormatLine(CHexDoc* pDoc, UINT nLine, CString& string);
void PrintPageHeader(CHexDoc* pDoc, CDC* pDC, UINT nPageNumber);
void PrintPage(CHexDoc* pDoc, CDC* pDC, UINT nPageNumber);
UINT m_cxWidth;
UINT m_cxOffset;
UINT m_nLinesPerPage;
UINT m_nLinesTotal;
UINT m_cyPrinter;
UINT m_cyScreen;
CFont m_fontPrinter;
CFont m_fontScreen;
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};
本文介绍了一种将RGB颜色值转换为灰度值的算法,并提供了一个C++类实现示例,用于处理十六进制文档的数据读取与显示。通过特定公式计算红色、绿色和蓝色通道的加权平均值来获得灰度值。

被折叠的 条评论
为什么被折叠?



