10 个解决方案
#1
void CMyGraphCuts01View::OnZoomIn()
{
if (m_scale < 5)
m_scale ++;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
void CMyGraphCuts01View::OnZoomOut()
{
if (m_scale > 1)
m_scale --;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
请问高手,还需要怎么搞一下?
#2
是你OnDraw绘图有问题吧,先用默认背景色填充整个Client区域,FillSolidRect(),然后再StretchBlt()贴图
#3
Invalidate(1);
#4
高手,原来作者的效果是这样的:
我的是这样的:
怎么让这个客户区窗口自动适应图片呢?
#5
你是怎么响应这些逻辑代码的?通过鼠标拖动*拉伸还是,你要处理就是打开图片,自动让客户端适应图片的大小?
#6
就贴这些逻辑代码没法解决。贴出事件处理代码。
#7
每个放大和缩小操作都应该基于原图,
估计你不是.
比如一个图A, 放大2倍变成B, 你又将B放大2倍变成C. 又将C缩小2倍变成D(你以为会变成B), 又将D缩小2倍变成E(你以为会变成A).
实际上应该这样做.
A 放大2倍变成B
A放大4倍变成C
A放大2倍变成D
A不变
即所有操作都要基于原图. 而不是变换后的图.
如果你问为什么??
那是因为, 任何缩放算法都是会有损的, 即缩放都是在破坏原图, 这时你想恢复回来, 那就是破镜重圆---不可能.
估计你不是.
比如一个图A, 放大2倍变成B, 你又将B放大2倍变成C. 又将C缩小2倍变成D(你以为会变成B), 又将D缩小2倍变成E(你以为会变成A).
实际上应该这样做.
A 放大2倍变成B
A放大4倍变成C
A放大2倍变成D
A不变
即所有操作都要基于原图. 而不是变换后的图.
如果你问为什么??
那是因为, 任何缩放算法都是会有损的, 即缩放都是在破坏原图, 这时你想恢复回来, 那就是破镜重圆---不可能.
#8
我也是,读别人的代码,我看这个代码就没有对图片进行操作啊,直接操作的是窗口。
这个zoomin函数就是点击放大按钮时候的响应函数啊。
void CMyGraphCuts01View::OnZoomIn()
{
if (m_scale < 5)
m_scale ++;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
void CMyGraphCuts01View::OnZoomOut()
{
if (m_scale > 1)
m_scale --;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
#9
我贴的就是放大缩小的事件处理啊。
#10
求解决啊
// MyGraphCuts0.1View.cpp : CMyGraphCuts01View 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MyGraphCuts0.1.h"
#endif
#include "MyGraphCuts0.1Doc.h"
#include "MyGraphCuts0.1View.h"
#include "CvvImage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#ifndef DELETE_SAFE
#define DELETE_SAFE(x) {if ((x)) delete [](x); (x)=NULL;}
#endif
// CMyGraphCuts01View
IMPLEMENT_DYNCREATE(CMyGraphCuts01View, CView)
BEGIN_MESSAGE_MAP(CMyGraphCuts01View, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMyGraphCuts01View::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_BUTTON_ZOOMIN, OnZoomIn)
ON_COMMAND(ID_BUTTON_ZOOMOUT, OnZoomOut)
ON_WM_TIMER()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CMyGraphCuts01View 构造/析构
CMyGraphCuts01View::CMyGraphCuts01View()
{
// TODO: 在此处添加构造代码
m_image = NULL;
m_scale = 1;
m_isDraw = false;
m_stateBuffer = &m_state1Buffer;
}
CMyGraphCuts01View::~CMyGraphCuts01View()
{
}
BOOL CMyGraphCuts01View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// CMyGraphCuts01View 绘制
void CMyGraphCuts01View::OnDraw(CDC* pDC/*pDC*/)
{
CMyGraphCuts01Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
m_stateBuffer->drawDC(m_swapBuffer.GetDC(),0,0);
m_swapBuffer.strechDC(pDC,0,0,m_scale);
// TODO: add draw code for native data here
// CvvImage & img= pDoc->m_image;
//
// if (img.GetImage()!=0)
// {
// img.Show(pDC->GetSafeHdc(),0,0,img.GetImage()->width,img.GetImage()->height,0,0);
// }
// TODO: 在此处为本机数据添加绘制代码
}
//消息处理
void CMyGraphCuts01View::OnInitialUpdate()
{
CView::OnInitialUpdate();
CMyGraphCuts01Doc* pDoc = GetDocument();
if (pDoc->m_IsFileLoad)
{
CString file = pDoc->GetPathName();
CvvImage img;
if (!img.Load(file))
{
MessageBox("无法打开文件",NULL, MB_ICONSTOP|MB_OK);
pDoc->m_IsFileLoad = false;
return;
}
m_width = img.Width();
m_height = img.Height();
m_originalBuffer.initialize(m_width, m_height);
m_state1Buffer.initialize(m_width, m_height);
m_state2Buffer.initialize(m_width, m_height);
m_swapBuffer.initialize(m_width, m_height);
CRect rect(0,0,m_width,m_height);
img.DrawToHDC(m_originalBuffer.GetDC()->m_hDC,rect);
img.DrawToHDC(m_state1Buffer.GetDC()->m_hDC,rect);
img.DrawToHDC(m_state2Buffer.GetDC()->m_hDC,rect);
CFrameWnd* pFrame = GetParentFrame();
pFrame->CalcWindowRect(rect);
rect.MoveToXY(0,0);
pFrame->MoveWindow(rect);
int size = m_width * img.Height() * 3;
DELETE_SAFE(m_image);
m_image = new BYTE[size];
BYTE* src = (BYTE*) img.GetImage()->imageData;
int widthStep = img.GetImage()->widthStep;
int width3 = m_width * 3;
for (int i=0;i<m_height;i++)
{
for (int j=0;j<width3;j++)
m_image[i*width3+j] = src[i*widthStep+j];
}
//m_maskManager.initMask(m_width, m_height, CGrabcutModel::UND );
//m_graphModel.setImage(m_image, m_width, m_height );
//m_graphModel.setMask(m_maskManager.getMask());
SetTimer(1, 1000, NULL);
//周期性触发
}
}
// CMyGraphCuts01View 打印
void CMyGraphCuts01View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CMyGraphCuts01View::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CMyGraphCuts01View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CMyGraphCuts01View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void CMyGraphCuts01View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CMyGraphCuts01View 诊断
#ifdef _DEBUG
void CMyGraphCuts01View::AssertValid() const
{
CView::AssertValid();
}
void CMyGraphCuts01View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyGraphCuts01Doc* CMyGraphCuts01View::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyGraphCuts01Doc)));
return (CMyGraphCuts01Doc*)m_pDocument;
}
#endif //_DEBUG
// CMyGraphCuts01View 消息处理程序
void CMyGraphCuts01View::OnLButtonDown(UINT nFlags, CPoint point)
{
m_isDraw = true;
SetCapture();
CView::OnLButtonDown(nFlags, point);
}
void CMyGraphCuts01View::OnLButtonUp(UINT nFlags, CPoint point)
{
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}
void CMyGraphCuts01View::OnRButtonDown(UINT nFlags, CPoint point)
{
m_isDraw = true;
//The return value is a handle to the window that had previously captured the mouse.
SetCapture();
CView::OnRButtonDown(nFlags, point);
}
void CMyGraphCuts01View::OnRButtonUp(UINT nFlags, CPoint point)
{
CView::OnRButtonUp(nFlags, point);
}
void CMyGraphCuts01View::OnMouseMove(UINT nFlags, CPoint point)
{
CView::OnMouseMove(nFlags, point);
point.x /= m_scale;
point.y /= m_scale;
if (! m_isDraw)
return;
else if (!(nFlags & MK_LBUTTON) && !(nFlags & MK_RBUTTON) )
{
ReleaseCapture();
m_isDraw = false;
} else if (nFlags & MK_LBUTTON)
{
m_state1Buffer.setPixel(point.x, point.y, 5, RGB(0,0,255));
m_state2Buffer.setPixel(point.x, point.y, 5, RGB(0,0,255));
//m_maskManager.setMask(point.x, point.y, 5, CGrabcutModel::OBJ);
} else
{
m_state1Buffer.setPixel(point.x, point.y, 5, RGB(255,0,0));
m_state2Buffer.setPixel(point.x, point.y, 5, RGB(255,0,0));
//m_maskManager.setMask(point.x, point.y, 5, CGrabcutModel::BKG);
}
Invalidate(0);
}
void CMyGraphCuts01View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 1:
if (m_stateBuffer == &m_state1Buffer)
m_stateBuffer = &m_state2Buffer;
else
m_stateBuffer = &m_state1Buffer;
Invalidate(0);
break;
default:
CView::OnTimer(nIDEvent);
}
}
HBRUSH CMyGraphCuts01View::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
//在MFC类库提供了CWnd::OnCtlColor函数,在工作框架的子窗口被重画时将调用该成员函数
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CMyGraphCuts01View::OnZoomIn()
{
if (m_scale < 5)
m_scale ++;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
void CMyGraphCuts01View::OnZoomOut()
{
if (m_scale > 1)
m_scale --;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
#1
void CMyGraphCuts01View::OnZoomIn()
{
if (m_scale < 5)
m_scale ++;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
void CMyGraphCuts01View::OnZoomOut()
{
if (m_scale > 1)
m_scale --;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
请问高手,还需要怎么搞一下?
#2
是你OnDraw绘图有问题吧,先用默认背景色填充整个Client区域,FillSolidRect(),然后再StretchBlt()贴图
#3
Invalidate(1);
#4
高手,原来作者的效果是这样的:
我的是这样的:
怎么让这个客户区窗口自动适应图片呢?
#5
你是怎么响应这些逻辑代码的?通过鼠标拖动*拉伸还是,你要处理就是打开图片,自动让客户端适应图片的大小?
#6
就贴这些逻辑代码没法解决。贴出事件处理代码。
#7
每个放大和缩小操作都应该基于原图,
估计你不是.
比如一个图A, 放大2倍变成B, 你又将B放大2倍变成C. 又将C缩小2倍变成D(你以为会变成B), 又将D缩小2倍变成E(你以为会变成A).
实际上应该这样做.
A 放大2倍变成B
A放大4倍变成C
A放大2倍变成D
A不变
即所有操作都要基于原图. 而不是变换后的图.
如果你问为什么??
那是因为, 任何缩放算法都是会有损的, 即缩放都是在破坏原图, 这时你想恢复回来, 那就是破镜重圆---不可能.
估计你不是.
比如一个图A, 放大2倍变成B, 你又将B放大2倍变成C. 又将C缩小2倍变成D(你以为会变成B), 又将D缩小2倍变成E(你以为会变成A).
实际上应该这样做.
A 放大2倍变成B
A放大4倍变成C
A放大2倍变成D
A不变
即所有操作都要基于原图. 而不是变换后的图.
如果你问为什么??
那是因为, 任何缩放算法都是会有损的, 即缩放都是在破坏原图, 这时你想恢复回来, 那就是破镜重圆---不可能.
#8
我也是,读别人的代码,我看这个代码就没有对图片进行操作啊,直接操作的是窗口。
这个zoomin函数就是点击放大按钮时候的响应函数啊。
void CMyGraphCuts01View::OnZoomIn()
{
if (m_scale < 5)
m_scale ++;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
void CMyGraphCuts01View::OnZoomOut()
{
if (m_scale > 1)
m_scale --;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
#9
我贴的就是放大缩小的事件处理啊。
#10
求解决啊
// MyGraphCuts0.1View.cpp : CMyGraphCuts01View 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MyGraphCuts0.1.h"
#endif
#include "MyGraphCuts0.1Doc.h"
#include "MyGraphCuts0.1View.h"
#include "CvvImage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#ifndef DELETE_SAFE
#define DELETE_SAFE(x) {if ((x)) delete [](x); (x)=NULL;}
#endif
// CMyGraphCuts01View
IMPLEMENT_DYNCREATE(CMyGraphCuts01View, CView)
BEGIN_MESSAGE_MAP(CMyGraphCuts01View, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMyGraphCuts01View::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_BUTTON_ZOOMIN, OnZoomIn)
ON_COMMAND(ID_BUTTON_ZOOMOUT, OnZoomOut)
ON_WM_TIMER()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
// CMyGraphCuts01View 构造/析构
CMyGraphCuts01View::CMyGraphCuts01View()
{
// TODO: 在此处添加构造代码
m_image = NULL;
m_scale = 1;
m_isDraw = false;
m_stateBuffer = &m_state1Buffer;
}
CMyGraphCuts01View::~CMyGraphCuts01View()
{
}
BOOL CMyGraphCuts01View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// CMyGraphCuts01View 绘制
void CMyGraphCuts01View::OnDraw(CDC* pDC/*pDC*/)
{
CMyGraphCuts01Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
m_stateBuffer->drawDC(m_swapBuffer.GetDC(),0,0);
m_swapBuffer.strechDC(pDC,0,0,m_scale);
// TODO: add draw code for native data here
// CvvImage & img= pDoc->m_image;
//
// if (img.GetImage()!=0)
// {
// img.Show(pDC->GetSafeHdc(),0,0,img.GetImage()->width,img.GetImage()->height,0,0);
// }
// TODO: 在此处为本机数据添加绘制代码
}
//消息处理
void CMyGraphCuts01View::OnInitialUpdate()
{
CView::OnInitialUpdate();
CMyGraphCuts01Doc* pDoc = GetDocument();
if (pDoc->m_IsFileLoad)
{
CString file = pDoc->GetPathName();
CvvImage img;
if (!img.Load(file))
{
MessageBox("无法打开文件",NULL, MB_ICONSTOP|MB_OK);
pDoc->m_IsFileLoad = false;
return;
}
m_width = img.Width();
m_height = img.Height();
m_originalBuffer.initialize(m_width, m_height);
m_state1Buffer.initialize(m_width, m_height);
m_state2Buffer.initialize(m_width, m_height);
m_swapBuffer.initialize(m_width, m_height);
CRect rect(0,0,m_width,m_height);
img.DrawToHDC(m_originalBuffer.GetDC()->m_hDC,rect);
img.DrawToHDC(m_state1Buffer.GetDC()->m_hDC,rect);
img.DrawToHDC(m_state2Buffer.GetDC()->m_hDC,rect);
CFrameWnd* pFrame = GetParentFrame();
pFrame->CalcWindowRect(rect);
rect.MoveToXY(0,0);
pFrame->MoveWindow(rect);
int size = m_width * img.Height() * 3;
DELETE_SAFE(m_image);
m_image = new BYTE[size];
BYTE* src = (BYTE*) img.GetImage()->imageData;
int widthStep = img.GetImage()->widthStep;
int width3 = m_width * 3;
for (int i=0;i<m_height;i++)
{
for (int j=0;j<width3;j++)
m_image[i*width3+j] = src[i*widthStep+j];
}
//m_maskManager.initMask(m_width, m_height, CGrabcutModel::UND );
//m_graphModel.setImage(m_image, m_width, m_height );
//m_graphModel.setMask(m_maskManager.getMask());
SetTimer(1, 1000, NULL);
//周期性触发
}
}
// CMyGraphCuts01View 打印
void CMyGraphCuts01View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CMyGraphCuts01View::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CMyGraphCuts01View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CMyGraphCuts01View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void CMyGraphCuts01View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CMyGraphCuts01View 诊断
#ifdef _DEBUG
void CMyGraphCuts01View::AssertValid() const
{
CView::AssertValid();
}
void CMyGraphCuts01View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyGraphCuts01Doc* CMyGraphCuts01View::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyGraphCuts01Doc)));
return (CMyGraphCuts01Doc*)m_pDocument;
}
#endif //_DEBUG
// CMyGraphCuts01View 消息处理程序
void CMyGraphCuts01View::OnLButtonDown(UINT nFlags, CPoint point)
{
m_isDraw = true;
SetCapture();
CView::OnLButtonDown(nFlags, point);
}
void CMyGraphCuts01View::OnLButtonUp(UINT nFlags, CPoint point)
{
ReleaseCapture();
CView::OnLButtonUp(nFlags, point);
}
void CMyGraphCuts01View::OnRButtonDown(UINT nFlags, CPoint point)
{
m_isDraw = true;
//The return value is a handle to the window that had previously captured the mouse.
SetCapture();
CView::OnRButtonDown(nFlags, point);
}
void CMyGraphCuts01View::OnRButtonUp(UINT nFlags, CPoint point)
{
CView::OnRButtonUp(nFlags, point);
}
void CMyGraphCuts01View::OnMouseMove(UINT nFlags, CPoint point)
{
CView::OnMouseMove(nFlags, point);
point.x /= m_scale;
point.y /= m_scale;
if (! m_isDraw)
return;
else if (!(nFlags & MK_LBUTTON) && !(nFlags & MK_RBUTTON) )
{
ReleaseCapture();
m_isDraw = false;
} else if (nFlags & MK_LBUTTON)
{
m_state1Buffer.setPixel(point.x, point.y, 5, RGB(0,0,255));
m_state2Buffer.setPixel(point.x, point.y, 5, RGB(0,0,255));
//m_maskManager.setMask(point.x, point.y, 5, CGrabcutModel::OBJ);
} else
{
m_state1Buffer.setPixel(point.x, point.y, 5, RGB(255,0,0));
m_state2Buffer.setPixel(point.x, point.y, 5, RGB(255,0,0));
//m_maskManager.setMask(point.x, point.y, 5, CGrabcutModel::BKG);
}
Invalidate(0);
}
void CMyGraphCuts01View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 1:
if (m_stateBuffer == &m_state1Buffer)
m_stateBuffer = &m_state2Buffer;
else
m_stateBuffer = &m_state1Buffer;
Invalidate(0);
break;
default:
CView::OnTimer(nIDEvent);
}
}
HBRUSH CMyGraphCuts01View::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
//在MFC类库提供了CWnd::OnCtlColor函数,在工作框架的子窗口被重画时将调用该成员函数
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CMyGraphCuts01View::OnZoomIn()
{
if (m_scale < 5)
m_scale ++;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}
void CMyGraphCuts01View::OnZoomOut()
{
if (m_scale > 1)
m_scale --;
CRect rect;
CFrameWnd* pFrame = GetParentFrame();
pFrame->GetWindowRect(rect);
rect.right = rect.left + m_width * m_scale;
rect.bottom = rect.top + m_height * m_scale;
pFrame->CalcWindowRect(rect);
pFrame->MoveWindow(0,0,rect.Width(), rect.Height());
Invalidate(0);
}