📄 jpegshowview.cpp
字号:
// jpegshowView.cpp : implementation of the CJpegshowView class
//
#include "stdafx.h"
#include "jpegshow.h"
#include "jpegshowDoc.h"
#include "jpegshowView.h"
#include"Dib.h"
#include "Jpeg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJpegshowView
IMPLEMENT_DYNCREATE(CJpegshowView, CView)
BEGIN_MESSAGE_MAP(CJpegshowView, CView)
//{{AFX_MSG_MAP(CJpegshowView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJpegshowView construction/destruction
CJpegshowView::CJpegshowView()
{
// TODO: add construction code here
}
CJpegshowView::~CJpegshowView()
{
}
BOOL CJpegshowView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CJpegshowView drawing
void CJpegshowView::OnDraw(CDC* pDC)
{
CJpegshowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
BeginWaitCursor();
if (!m_dib.IsEmpty())
m_dib.Display(pDC, 0, 0);
EndWaitCursor();
}
/////////////////////////////////////////////////////////////////////////////
// CJpegshowView diagnostics
#ifdef _DEBUG
void CJpegshowView::AssertValid() const
{
CView::AssertValid();
}
void CJpegshowView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CJpegshowDoc* CJpegshowView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CJpegshowDoc)));
return (CJpegshowDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CJpegshowView message handlers
void CJpegshowView::OnFileOpen()
{
// TODO: Add your command handler code here
CString fileName;
CString szOpenFilter = "图象文件|*.bmp; *.dib; *.jpg; *.jpe; *.jpeg; |位图文件 (*.bmp;*.dib)|*.bmp; *.dib|JPEG文件 (*.jpg;*.jpe;*.jpeg)|*.jpg; *.jpe; *.jpeg|All Files (*.*)|*.*||";
CFileDialog FileDlg(TRUE,NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szOpenFilter);
if (FileDlg.DoModal() == IDOK)
{
fileName=FileDlg.GetPathName();
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath((LPCSTR)fileName, drive, dir, fname, ext);
CJpeg jpeg;
if (! stricmp(ext, ".jpg") ||
! stricmp(ext, ".jpe") ||
! stricmp(ext, ".jpeg") )
{
if (! jpeg.Load(fileName))
AfxMessageBox("false");
HDIB hDIB = CopyHandle(jpeg.m_dib.GetHandle());
m_dib.Attach(hDIB);
}
if (! stricmp(ext, ".bmp") ||
! stricmp(ext, ".dib") )
{ if (!m_dib.Load(fileName))
AfxMessageBox("false");
HDIB hDIB = CopyHandle(m_dib.GetHandle());
m_dib.Attach(hDIB);
}
}
Invalidate(TRUE);
}
void CJpegshowView::OnFileSaveAs()
{
// TODO: Add your command handler code here
CString fileName;
CString szSaveFilter= "位图 (*.bmp;*.dib)|*.bmp; *.dib|JPEG文件 (*.jpg;*.jpe;*.jpeg)|*.jpg; *.jpe; *.jpeg|All Files (*.*)|*.*||";
CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szSaveFilter);
if (FileDlg.DoModal() == IDOK)
{
fileName=FileDlg.GetPathName();
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath((LPCSTR)fileName, drive, dir, fname, ext);
CJpeg jpeg;
if (! stricmp(ext, ".jpg") ||
! stricmp(ext, ".jpe") ||
! stricmp(ext, ".jpeg") )
{
//将文件存储为JPEG格式
jpeg.Save(fileName,&m_dib, TRUE, 75);
}
if (! stricmp(ext, ".bmp") ||
! stricmp(ext, ".dib") )
{
//将文件存储为BMP格式
m_dib.Save(fileName);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -