MFC 加载jpg图片
2014-05-19 17:05
169 查看
转载http://blog.sina.com.cn/s/blog_4ac0eb8101010ico.html
IPicture *m_picture;
OLE_XSIZE_HIMETRIC m_width;
OLE_YSIZE_HIMETRIC m_height;
BOOL m_IsShow;
2. 在Dlg.cpp的OnPaint函数中加入:
CPaintDC dc(this);
CFile m_file("D:\\1.jpg",CFile::modeRead );
//获取文件长度
DWORD m_filelen = m_file.GetLength();
//在堆上分配空间
HGLOBAL m_hglobal = GlobalAlloc(GMEM_MOVEABLE,m_filelen);
LPVOID pvdata = NULL;
//锁定堆空间,获取指向堆空间的指针
pvdata = GlobalLock(m_hglobal);
//将文件数据读区到堆中
m_file.ReadHuge(pvdata,m_filelen);
IStream* m_stream;
GlobalUnlock(m_hglobal);
//在堆中创建流对象
CreateStreamOnHGlobal(m_hglobal,TRUE,&m_stream);
//利用流加载图像
OleLoadPicture(m_stream,m_filelen,TRUE,IID_IPicture,(LPVOID*)&m_picture);
m_stream->Release();
m_picture->get_Width(&m_width);// 宽高,MM_HIMETRIC 模式,单位是0.01毫米
m_picture->get_Height(&m_height);
m_IsShow = TRUE;
m_file.Close();
if (m_IsShow==TRUE){
CRect rect;
GetClientRect(rect);
int nW, nH;
nW = (int)(rect.Width());
nH = (int)(rect.Height());
m_picture->Render(dc,0,0,nW,nH,0,m_height,m_width,-m_height,&rect);
}
CDialog::OnPaint();
IPicture *m_picture;
OLE_XSIZE_HIMETRIC m_width;
OLE_YSIZE_HIMETRIC m_height;
BOOL m_IsShow;
2. 在Dlg.cpp的OnPaint函数中加入:
CPaintDC dc(this);
CFile m_file("D:\\1.jpg",CFile::modeRead );
//获取文件长度
DWORD m_filelen = m_file.GetLength();
//在堆上分配空间
HGLOBAL m_hglobal = GlobalAlloc(GMEM_MOVEABLE,m_filelen);
LPVOID pvdata = NULL;
//锁定堆空间,获取指向堆空间的指针
pvdata = GlobalLock(m_hglobal);
//将文件数据读区到堆中
m_file.ReadHuge(pvdata,m_filelen);
IStream* m_stream;
GlobalUnlock(m_hglobal);
//在堆中创建流对象
CreateStreamOnHGlobal(m_hglobal,TRUE,&m_stream);
//利用流加载图像
OleLoadPicture(m_stream,m_filelen,TRUE,IID_IPicture,(LPVOID*)&m_picture);
m_stream->Release();
m_picture->get_Width(&m_width);// 宽高,MM_HIMETRIC 模式,单位是0.01毫米
m_picture->get_Height(&m_height);
m_IsShow = TRUE;
m_file.Close();
if (m_IsShow==TRUE){
CRect rect;
GetClientRect(rect);
int nW, nH;
nW = (int)(rect.Width());
nH = (int)(rect.Height());
m_picture->Render(dc,0,0,nW,nH,0,m_height,m_width,-m_height,&rect);
}
CDialog::OnPaint();
相关文章推荐
- MFC 加载jpg等图片
- MFC PICTURE控件加载JPG图片
- VC下加载JPG/GIF/PNG图片的两种方法
- 加载多种图片格式(gif,jpg,png.bmp)
- halcon加载图片到mfc
- [WM C++]从资源文件中加载显示png/jpg图片
- [WM C++]从资源文件中加载显示png/jpg图片
- 使用ATL库中的CImage类加载JPG图片作为对话框背景
- VC下加载JPG/GIF/PNG图片的两种方法
- C/C++:何以在程序中加载JPG图片?
- 如何在MFC窗口显示BMP和JPG图片
- 用API OleLoadPicture通过IStream来加载JPG、GIF格式的图片
- 用API OleLoadPicture通过IStream来加载JPG、GIF格式的图片
- VC下加载JPG/GIF/PNG图片的两种方法
- VC 下加载 JPG / JPEG / GIF / PNG 图片最简单的方法
- 转载:用API OleLoadPicture通过IStream来加载JPG、GIF格式的图片
- 急!WinCE下加载流式JPG图片
- halcon加载图片到mfc
- VC.NET从资源中加载图片(jpg,png)并显示
- 如何在数据中能加载.JPG格式的图片