📄 imageprocess.cpp
字号:
// ImageProcess.cpp : implementation file
//
#include "stdafx.h"
#include "bxt.h"
#include "ImageProcess.h"
#include "bxtdlg.h"
#include <math.h>
//#include "standardlength.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define COLORPIC
/////////////////////////////////////////////////////////////////////////////
// ImageProcess dialog
// ipath -> Image Path
ImageProcess::ImageProcess(char *sPath, CWnd* pParent /*=NULL*/)
: CDialog(ImageProcess::IDD, pParent)
{
//{{AFX_DATA_INIT(ImageProcess)
m_iCurPicIndex = 0;
//}}AFX_DATA_INIT
m_sPath = _T(sPath);
m_pCurrentPic = NULL;
m_pCurrentMark = NULL;
m_pPic[0] = new CPic;
m_bMarking = FALSE;
int i;
for (i = 0; i <= 101; i++) m_pMark[i] = NULL;
for (i = 0; i < 10; i++) m_bIsDynamic[i] = FALSE;
}
void
ImageProcess::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ImageProcess)
DDX_Control(pDX, IDC_CURPIC, m_edtCurPic);
DDX_Control(pDX, IDC_SCROLLBAR_PIC, m_vs);
DDX_Text(pDX, IDC_CURPIC, m_iCurPicIndex);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ImageProcess, CDialog)
//{{AFX_MSG_MAP(ImageProcess)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
ON_MESSAGE(WX_DSPIMG, SetDisp)
ON_MESSAGE(WX_DSPPRC, DispPrc)
ON_MESSAGE(WX_DSPMETA, DispMeasure)
ON_MESSAGE(WX_DSPZOOM, DispZoom)
ON_MESSAGE(WX_DSPSTRETCH, DispStretch)
ON_MESSAGE(WX_DSPCONBRI, ChgConBri)
ON_MESSAGE(WX_BSPWINPOS, ChgGryWin)
ON_MESSAGE(WX_CHGPALT, ChgPlatte)
ON_MESSAGE(WX_PLAYBACK, PlayBackAvi)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ImageProcess message handlers
void ImageProcess::DispMeasure(WPARAM wParm, LPARAM lParm)
{
if (NULL == m_pCurrentPic || 1 != DispStyle) return;
HWND hWnd = ff[1].GetSafeHwnd();
INT iAction = (INT)(wParm);
HWND hInfoWnd = (HWND)(lParm);
LPARAM lpArg2 = NULL;
if (ACTION_TEXT == iAction)
{
CBxtDlg *pMainWnd = (CBxtDlg *)AfxGetMainWnd();
lpArg2 = (LPARAM)(pMainWnd->dispmarking->GetDlgItem(IDC_EDIT_MARKING_TEXT)->GetSafeHwnd());
}
else if (ACTION_DELETE == iAction)
lpArg2 = (LPARAM)(GetSafeHwnd());
m_pCurrentMark->SetAction(iAction, lpArg2, hInfoWnd);
}
/*
是否拉伸,布尔值
*/
void ImageProcess::DispStretch(WPARAM wParm, LPARAM lParm)
{
// 拉伸
m_bStretch = wParm;
DrawImg();
}
/*
放大/缩小
*/
void
ImageProcess::DispZoom(WPARAM wParm, LPARAM lParm)
{
if (NULL == m_pCurrentPic || 1 != DispStyle) return;
CDC *pDC = ff[1].GetDC();
CRect rc;
ff[1].GetWindowRect(&rc);
m_pPic[m_iCurPicIndex]->SetZoom(pDC, float(wParm), rc.Width(), rc.Height());
m_pMark[m_iCurPicIndex]->SetTargetDCRect(rc);
m_pPic[m_iCurPicIndex]->ZoomBMP(pDC, 0, 0, rc.Width(), rc.Height(), 0, 0);
m_pMark[m_iCurPicIndex]->ReDraw(pDC->GetSafeHdc());
ReleaseDC(pDC);
}
void
ImageProcess::DispPrc(WPARAM wParm, LPARAM lParm)
{
if (NULL == m_pCurrentPic || m_iPicCount < 1) return;
m_pCurrentPic = m_pPic[m_iCurPicIndex];
m_pCurrentMark = m_pMark[m_iCurPicIndex];
int iAction = (int)(wParm);
switch (iAction)
{
case 1: // rotte left
m_pCurrentPic->RoteL();
break;
case 2: // rogte right
m_pCurrentPic->RoteR();
break;
case 3: // flip vertical
m_pCurrentPic->VertFlip();
break;
case 4: // flip harizantal
m_pCurrentPic->HFlip();
break;
case 5: // edge find
m_pCurrentPic->FindEdge();
break;
case 6: // restore org
m_pCurrentPic->ReLoad();
break;
}
DrawImg();
}
/*
设置显示方式
使用 wParm
设置值为:
1: one 2: Tile_V 3: Tile_H 4: four 6: six 9: nine
*/
void
ImageProcess::SetDisp(WPARAM wParm, LPARAM lParm)
{
int xCount, yCount;
int iPicPerPage;
int iPageCount;
int iCurrentPage;
int i, j;
CRect rect;
// if (DispStyle == int(wParm)) return;
if (NULL != m_pCurrentMark &&
FALSE == m_pCurrentMark->SetAction(ACTION_NOTHING, 0, NULL)) return;
DispStyle = wParm;
iPicPerPage = (3 == DispStyle) ? (2) : (DispStyle);
// Hide All Image Frame
for (i = 1; i <= 9; i++) ff[i].ShowWindow(SW_HIDE);
iPageCount = (m_iPicCount - 1) / iPicPerPage + 1;
iPageCount = (iPageCount > 1) ? (iPageCount) : (1);
iCurrentPage = (m_iCurPicIndex - 1) / iPicPerPage + 1;
iCurrentPage = (iCurrentPage > 1) ? (iCurrentPage) : (1);
m_vs.SetScrollRange(1, iPageCount);
m_vs.SetScrollPos(iCurrentPage);
m_iTopPicIndex = iPicPerPage * (iCurrentPage - 1) + 1;
/*
CString sInfo;
sInfo.Format("PageCount: %d, CurrentPage: %d, ScrollRange: (%d, %d), ScrollPos: %d, TopIndex: %d",
iPageCount, iCurrentPage, 1, iPageCount, iCurrentPage, m_iTopPicIndex);
AfxMessageBox(sInfo);
*/
switch (DispStyle)
{
case 1:
xCount = 1;
yCount = 1;
break;
case 2:
xCount = 2;
yCount = 1;
break;
case 3:
xCount = 1;
yCount = 2;
break;
case 4:
xCount = 2;
yCount = 2;
break;
case 6:
xCount = 2;
yCount = 3;
break;
case 9:
xCount = 3;
yCount = 3;
break;
default:
AfxMessageBox("Error DispStyle Value!");
return;
}
int iFrameWidth = m_PicRect.Width() / xCount;
int iFrameHeight = m_PicRect.Height() / yCount;
rect.SetRect(0, 0, iFrameWidth - 2, iFrameHeight - 2);
int iFrameIndex;
int iFrameX;
int iFrameY;
int iPicIndex;
for (i = 1; i <= xCount; i++) for (j = 1; j <= yCount; j++)
{
iFrameIndex = (j - 1) * xCount + i;
iFrameX = (i - 1) * iFrameWidth + 1;
iFrameY = (j - 1) * iFrameHeight + 1;
iPicIndex = m_iTopPicIndex + iFrameIndex - 1;
ff[iFrameIndex].MoveWindow(iFrameX, iFrameY, iFrameWidth - 2, iFrameHeight - 2);
ff[iFrameIndex].GetClientRect(&rect);
if (NULL != m_pMark[iPicIndex])
{
m_pMark[iPicIndex]->SetZoom((1 == DispStyle) ? (FALSE) : (TRUE));
m_pMark[iPicIndex]->SetTargetDCRect(rect);
m_pMark[iPicIndex]->SetTargetPICRect(rect);
}
ff[iFrameIndex].ShowWindow(SW_SHOW);
}
}
BOOL
ImageProcess::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD dwStyle; // 图片框风格
CRect rect; // 通用变量
CRect rcClient; // 客户端区域
CRect rcScrollBar; // 滚动条区域
CRect rcDCSource; // 源设备区域
int i; // 通用循环变量
// 获取去掉 VISIBLE 属性的图片框属性
dwStyle = GetDlgItem(IDC_IMGFRAME)->GetStyle();
dwStyle &= ~WS_VISIBLE;
// 动态创建不可见 CStatic Control 对象
rect.SetRect(0, 0, 1, 1);
for (i = 1; i < 10; i++) ff[i].Create("", dwStyle, rect, this, 2010 + i - 1);
// 获取客户端区域的位置
GetClientRect(&rcClient);
// 获取滚动条区域
m_vs.GetWindowRect(&rcScrollBar);
rect.SetRect(rcClient.right - rcScrollBar.Width(), rcClient.top, rcClient.right, rcClient.bottom);
m_vs.MoveWindow(&rect);
// 设置图片区域的位置
m_PicRect = rcClient;
m_PicRect.right -= rcScrollBar.Width();
// 初始化图片框位置
ff[1].MoveWindow(1, 1, m_PicRect.Width() - 2, m_PicRect.Height() - 2);
// 初始化 CMeta 类
CMeta::InitMeta();
// 获取源设备区域
ff[1].GetClientRect(&m_rcSourceDCRect);
ff[1].ShowWindow(SW_SHOW);
m_iPicCount = 0; // 没有图象
m_bStretch = FALSE; // 默认为不拉伸
ReFresh(); // 按照当前路径(重新)载入图象
return TRUE;
}
void
ImageProcess::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);
if (1 != DispStyle) // 多幅图象显示
{
INT iOldCurPicIndex = m_iCurPicIndex; // 上次当前图象索引
INT iFrameIndex = GetFrameIndex(point); // 被电击的图象索引
INT iPicIndex = m_iTopPicIndex + iFrameIndex - 1;
if ((iOldCurPicIndex !=iPicIndex) && (iPicIndex >= 1) && (iPicIndex <= m_iPicCount))
SetCurrentPicture(iPicIndex);
}
else
{
m_bMarking = TRUE;
SetCapture();
HWND hWnd = ff[1].GetSafeHwnd();
HWND hContainWnd = GetSafeHwnd();
ClientToScreen(&point);
ff[1].ScreenToClient(&point);
m_pCurrentMark->SetOutputWindow(hContainWnd, hWnd);
m_pCurrentMark->MouseDown(nFlags, point);
}
}
VOID
ImageProcess::OnMouseMove(UINT nFlags, CPoint point)
{
CDialog::OnMouseMove(nFlags, point);
if (FALSE != m_bMarking)
{
ClientToScreen(&point);
ff[1].ScreenToClient(&point);
m_pCurrentMark->MouseMove(nFlags, point);
}
}
void
ImageProcess::OnLButtonUp(UINT nFlags, CPoint point)
{
CDialog::OnLButtonUp(nFlags, point);
if (FALSE != m_bMarking)
{
::ReleaseCapture();
CWnd *pInfoWnd = ((CBxtDlg *)AfxGetMainWnd())->dispmeasure->GetDlgItem(IDC_EDIT_STATE);
CPoint pt = point;
ClientToScreen(&pt);
ff[1].ScreenToClient(&pt);
m_pCurrentMark->MouseUp(nFlags, point, pInfoWnd);
m_bMarking = FALSE;
}
}
void
ImageProcess::OnPaint()
{
CPaintDC dc(this); // device context for painting
DrawImg();
}
BOOL
ImageProcess::ReFresh(char *sNewPath)
{
// 释放资源
CleanUp();
// 设置路径
if (NULL != sNewPath && '\0' != sNewPath[0]) m_sPath = sNewPath;
if (m_sPath.IsEmpty()) return (FALSE);
CHAR sPicFile[1000] = "";
CHAR sMarkFile[1000] = "";
CHAR *sPathBuffer = m_sPath.GetBuffer(m_sPath.GetLength());
FILE *fp = NULL;
int iPicIndex;
// 计算图象总数并打开图象
for (iPicIndex = 1; iPicIndex <= 100; iPicIndex++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -