highgui.lib cxcore.lib cv.lib ml.lib cvaux.lib
#include "cv.h"
#include "highgui.h"
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMFCOPENCVDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
//}}AFX_VIRTUAL
public:
CImage m_img;
/
BOOL CMFCOPENCVDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
m_img.Load(lpszPathName);
return TRUE;
}
BOOL CMFCOPENCVDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
// TODO: Add your specialized code here and/or call the base class
m_img.Save(lpszPathName);
return CDocument::OnSaveDocument(lpszPathName);
}
//
void CMFCOPENCVView::OnDraw(CDC* pDC)
{
CMFCOPENCVDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CImage & img=pDoc->m_img;
HDC hDC=pDC->GetSafeHdc();
CRect rect(0,0,img.Width(),img.Height());
img.DrawToHDC(hDC,&rect);
}
//
VC++用CImage中Save函数保存图像后为什么为0字节?
经调试,问题在于VC本身
将return CDocument::OnSaveDocument(lpszPathName); 改为
return TRUE; 即可