📄 jpeglibtestdlg.cpp
字号:
// JpegLibTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "JpegLibTest.h"
#include "JpegLibTestDlg.h"
#include "STScreenBuffer.h"
#include "ByteArray.h"
extern "C" {
#include "../JpegLib/jpeglib.h"
}
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJpegLibTestDlg dialog
CJpegLibTestDlg::CJpegLibTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJpegLibTestDlg::IDD, pParent), m_hBitmap(0)
{
//{{AFX_DATA_INIT(CJpegLibTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CJpegLibTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJpegLibTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJpegLibTestDlg, CDialog)
//{{AFX_MSG_MAP(CJpegLibTestDlg)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJpegLibTestDlg message handlers
BOOL CJpegLibTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
m_hBitmap = LoadImage(_T("\\My Documents\\t.jpg"));
if (! m_hBitmap) {
return FALSE;
}
return TRUE; // return TRUE unless you set the focus to a control
}
HBITMAP CJpegLibTestDlg::LoadImage(const CString &strFileName)
{
FILE * pFile;
JSAMPARRAY pBuffer;
int nRowSize;
ByteArray imageData(320*240*3);
struct jpeg_error_mgr jerr;
struct jpeg_decompress_struct cinfo;
if ((pFile = _tfopen(strFileName, _T("rb"))) == NULL) {
CString strError;
strError.Format(_T("Can't open file '%s'"), strFileName);
AfxMessageBox(strError);
return 0;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, pFile);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
nRowSize = cinfo.output_width * cinfo.output_components;
pBuffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, nRowSize, 1);
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, pBuffer, 1);
imageData.Append(pBuffer[0], nRowSize);
}
HBITMAP hBitmap = CSTScreenBuffer::CreateBitmapByRGBArray(imageData.GetData(), cinfo.output_width, cinfo.output_height);
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(pFile);
return hBitmap;
}
void CJpegLibTestDlg::OnPaint()
{
CPaintDC dc(this);
if (m_hBitmap) {
CDC memDc;
VERIFY(memDc.CreateCompatibleDC(&dc));
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(), m_hBitmap);
VERIFY(dc.BitBlt(0, 0, 240, 320, &memDc, 0, 0, SRCCOPY));
::SelectObject(memDc.GetSafeHdc(), hOldBitmap);
VERIFY( memDc.DeleteDC() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -