怎么用opencv实现在mfc中图像打开和保存?
1个回答
展开全部
// OpenCVMFCView.h : interface of the COpenCVMFCView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_OPENCVMFCVIEW_H__D4F24E70_1F6C_401E_8DA2_77007D17F49F__INCLUDED_)
#define AFX_OPENCVMFCVIEW_H__D4F24E70_1F6C_401E_8DA2_77007D17F49F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class COpenCVMFCView : public CView
{
protected: // create from serialization only
COpenCVMFCView();
DECLARE_DYNCREATE(COpenCVMFCView)
// Attributes
public:
COpenCVMFCDoc* GetDocument();
// Operations
public:
CImage view_img;//CImage结构体 在view类与其他类之间图像调用
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(COpenCVMFCView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~COpenCVMFCView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(COpenCVMFCView)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in OpenCVMFCView.cpp
inline COpenCVMFCDoc* COpenCVMFCView::GetDocument()
{ return (COpenCVMFCDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_OPENCVMFCVIEW_H__D4F24E70_1F6C_401E_8DA2_77007D17F49F__INCLUDED_)
// OpenCVMFCView.cpp : implementation of the COpenCVMFCView class
//
#include "stdafx.h"
#include "OpenCVMFC.h"
#include "OpenCVMFCDoc.h"
#include "OpenCVMFCView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView
IMPLEMENT_DYNCREATE(COpenCVMFCView, CView)
BEGIN_MESSAGE_MAP(COpenCVMFCView, CView)
//{{AFX_MSG_MAP(COpenCVMFCView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView construction/destruction
COpenCVMFCView::COpenCVMFCView()
{
// TODO: add construction code here
}
COpenCVMFCView::~COpenCVMFCView()
{
}
BOOL COpenCVMFCView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView drawing
void COpenCVMFCView::OnDraw(CDC* pDC)
{
//COpenCVMFCDoc* pDoc = GetDocument();
//ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//在视图类显示
CRect dc_r;
GetClientRect(&dc_r);
view_img.DrawToHDC(pDC->GetSafeHdc(),dc_r);
}
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView printing
BOOL COpenCVMFCView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void COpenCVMFCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void COpenCVMFCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView diagnostics
#ifdef _DEBUG
void COpenCVMFCView::AssertValid() const
{
CView::AssertValid();
}
void COpenCVMFCView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
COpenCVMFCDoc* COpenCVMFCView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COpenCVMFCDoc)));
return (COpenCVMFCDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView message handlers
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_OPENCVMFCVIEW_H__D4F24E70_1F6C_401E_8DA2_77007D17F49F__INCLUDED_)
#define AFX_OPENCVMFCVIEW_H__D4F24E70_1F6C_401E_8DA2_77007D17F49F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class COpenCVMFCView : public CView
{
protected: // create from serialization only
COpenCVMFCView();
DECLARE_DYNCREATE(COpenCVMFCView)
// Attributes
public:
COpenCVMFCDoc* GetDocument();
// Operations
public:
CImage view_img;//CImage结构体 在view类与其他类之间图像调用
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(COpenCVMFCView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~COpenCVMFCView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(COpenCVMFCView)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in OpenCVMFCView.cpp
inline COpenCVMFCDoc* COpenCVMFCView::GetDocument()
{ return (COpenCVMFCDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_OPENCVMFCVIEW_H__D4F24E70_1F6C_401E_8DA2_77007D17F49F__INCLUDED_)
// OpenCVMFCView.cpp : implementation of the COpenCVMFCView class
//
#include "stdafx.h"
#include "OpenCVMFC.h"
#include "OpenCVMFCDoc.h"
#include "OpenCVMFCView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView
IMPLEMENT_DYNCREATE(COpenCVMFCView, CView)
BEGIN_MESSAGE_MAP(COpenCVMFCView, CView)
//{{AFX_MSG_MAP(COpenCVMFCView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView construction/destruction
COpenCVMFCView::COpenCVMFCView()
{
// TODO: add construction code here
}
COpenCVMFCView::~COpenCVMFCView()
{
}
BOOL COpenCVMFCView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView drawing
void COpenCVMFCView::OnDraw(CDC* pDC)
{
//COpenCVMFCDoc* pDoc = GetDocument();
//ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//在视图类显示
CRect dc_r;
GetClientRect(&dc_r);
view_img.DrawToHDC(pDC->GetSafeHdc(),dc_r);
}
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView printing
BOOL COpenCVMFCView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void COpenCVMFCView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void COpenCVMFCView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView diagnostics
#ifdef _DEBUG
void COpenCVMFCView::AssertValid() const
{
CView::AssertValid();
}
void COpenCVMFCView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
COpenCVMFCDoc* COpenCVMFCView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COpenCVMFCDoc)));
return (COpenCVMFCDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// COpenCVMFCView message handlers
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询