📄 02824227view.cpp
字号:
// 02824227View.cpp : implementation of the CMy02824227View class
//
#include "stdafx.h"
#include "02824227.h"
#include "02824227Doc.h"
#include "02824227View.h"
#include "dibapi.h"
#include "Dlg_02824227.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy02824227View
IMPLEMENT_DYNCREATE(CMy02824227View, CView)
BEGIN_MESSAGE_MAP(CMy02824227View, CView)
//{{AFX_MSG_MAP(CMy02824227View)
ON_COMMAND(ID_VIEW_Intensity, OnVIEWIntensity)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy02824227View construction/destruction
CMy02824227View::CMy02824227View()
{
// TODO: add construction code here
}
CMy02824227View::~CMy02824227View()
{
}
BOOL CMy02824227View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMy02824227View drawing
void CMy02824227View::OnDraw(CDC* pDC)
{
// 显示等待光标
BeginWaitCursor();
// 获取文档
CMy02824227Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//锁定DIB
lpDIB=(LPSTR)::GlobalLock((HGLOBAL)pDoc->GetHDIB());
//找到DIB图像像素的起始位置
lpDIBBits=::FindDIBBits(lpDIB);
height=::DIBHeight(lpDIB);
width=::DIBWidth(lpDIB);
// 指向BITMAPINFO结构的指针(Win3.0)
LPBITMAPINFO lpbmi;
// 获取指向BITMAPINFO结构的指针(Win3.0)
lpbmi = (LPBITMAPINFO)lpDIB;
// 计算图像每行的字节数
lLineBytes = WIDTHBYTES(width * 8);
LONG i,j;
LONG R,G,B;
//打点显示
for (i = 0; i < height; i ++)
{
for (j = 0; j < width; j ++)
{
// 指向图像指针
lpSrc = (unsigned char *)lpDIBBits + lLineBytes * i + j;
//查询颜色查找表LUT
R=lpbmi->bmiColors[*lpSrc].rgbRed;
G=lpbmi->bmiColors[*lpSrc].rgbGreen;
B=lpbmi->bmiColors[*lpSrc].rgbBlue;
pDC->SetPixel(j,height-i,RGB(R,G,B));
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CMy02824227View printing
BOOL CMy02824227View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMy02824227View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMy02824227View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMy02824227View diagnostics
#ifdef _DEBUG
void CMy02824227View::AssertValid() const
{
CView::AssertValid();
}
void CMy02824227View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMy02824227Doc* CMy02824227View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy02824227Doc)));
return (CMy02824227Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMy02824227View message handlers
void CMy02824227View::OnVIEWIntensity()
{
// TODO: Add your command handler code here
// 查看当前图像灰度直方图
// 获取文档
CMy02824227Doc* pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
// 指向DIB象素指针
LPSTR lpDIBBits;
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
// 找到DIB图像象素起始位置
lpDIBBits = ::FindDIBBits(lpDIB);
// 判断是否是8-bpp位图(这里为了方便,只处理8-bpp位图,其它的可以类推)
if (::DIBNumColors(lpDIB) != 256)
{
// 提示用户
MessageBox("目前只支持查看256色位图灰度直方图!", "系统提示" , MB_ICONINFORMATION | MB_OK);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
// 返回
return;
}
// 更改光标形状
BeginWaitCursor();
// 创建对话框
Dlg_02824227 dlgPara;
// 初始化变量值
dlgPara.m_lpDIBBits = lpDIBBits;
dlgPara.m_lWidth = ::DIBWidth(lpDIB);
dlgPara.m_lHeight = ::DIBHeight(lpDIB);
dlgPara.m_iLowGray = 0;
dlgPara.m_iUpGray = 255;
// 显示对话框,提示用户设定平移量
if (dlgPara.DoModal() != IDOK)
{
// 返回
return;
}
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
// 恢复光标
//EndWaitCursor();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -