VC++ 2005中显示jpg,bmp,gif图像的方法
2008-03-26 10:41
465 查看
IPicture接口是Window95及以上操作系统支持的一个COM接口,它用来操作各种在WINDOWS常见的图像格式。如,BMP、JPEG、GIF等许多文件格式都能识别。使用很方便。但是可能很多朋友对这个接口并不很熟悉,或者不太了解对COM接口的操作。
使用方法:
CPicture pic;
pic.Load(路径);
pic.Render(&dc,&CRect(10,10,200,200));
picture.h
#pragma once
#include <atlbase.h>
// Picture object--encapsulates IPicture
//
Picture.cpp
#include "StdAfx.h"
#include "Picture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CPicture implementation
//
// Load from resource. Looks for "IMAGE" type.
//
BOOL CPicture::Load(UINT nIDRes)
// Load from path name.
//
BOOL CPicture::Load(LPCTSTR pszPathName)
// Load from CFile
//
BOOL CPicture::Load(CFile& file)
// Load from archive--create stream and load from stream.
//
BOOL CPicture::Load(CArchive& ar)
// Load from stream (IStream). This is the one that really does it: call
// OleLoadPicture to do the work.
//
BOOL CPicture::Load(IStream* pstm)
// Render to device context. Covert to HIMETRIC for IPicture.
//
BOOL CPicture::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const
// Get image size in pixels. Converts from HIMETRIC to device coords.
//
CSize CPicture::GetImageSize(CDC* pDC) const
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!m_spIPicture)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return CSize(0,0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LONG hmWidth, hmHeight; // HIMETRIC units
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_spIPicture->get_Width(&hmWidth);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_spIPicture->get_Height(&hmHeight);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CSize sz(hmWidth,hmHeight);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (pDC==NULL) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CWindowDC dc(NULL);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dc.HIMETRICtoDP(&sz); // convert to pixels
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} else ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pDC->HIMETRICtoDP(&sz);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return sz;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
使用方法:
CPicture pic;
pic.Load(路径);
pic.Render(&dc,&CRect(10,10,200,200));
picture.h
#pragma once
#include <atlbase.h>
// Picture object--encapsulates IPicture
//
Picture.cpp
#include "StdAfx.h"
#include "Picture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CPicture implementation
//
// Load from resource. Looks for "IMAGE" type.
//
BOOL CPicture::Load(UINT nIDRes)
// Load from path name.
//
BOOL CPicture::Load(LPCTSTR pszPathName)
// Load from CFile
//
BOOL CPicture::Load(CFile& file)
// Load from archive--create stream and load from stream.
//
BOOL CPicture::Load(CArchive& ar)
// Load from stream (IStream). This is the one that really does it: call
// OleLoadPicture to do the work.
//
BOOL CPicture::Load(IStream* pstm)
// Render to device context. Covert to HIMETRIC for IPicture.
//
BOOL CPicture::Render(CDC* pDC, CRect rc, LPCRECT prcMFBounds) const
// Get image size in pixels. Converts from HIMETRIC to device coords.
//
CSize CPicture::GetImageSize(CDC* pDC) const
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (!m_spIPicture)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return CSize(0,0);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
LONG hmWidth, hmHeight; // HIMETRIC units
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_spIPicture->get_Width(&hmWidth);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
m_spIPicture->get_Height(&hmHeight);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CSize sz(hmWidth,hmHeight);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if (pDC==NULL) ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CWindowDC dc(NULL);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
dc.HIMETRICtoDP(&sz); // convert to pixels
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
} else ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
pDC->HIMETRICtoDP(&sz);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return sz;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
相关文章推荐
- VC中导入图像(BMP,JPG,GIF)并显示的方法
- VC 中BMP、JPG、GIF图像的显示
- VC下显示JPG,BMP,GIF等图像格式
- vc显示jpg,gif图像简单方法
- VC 中BMP、JPG、GIF图像的显示
- VC下显示JPG,BMP,GIF等图像格式(转载)
- vc显示jpg,gif图像简单方法
- vc显示jpg,gif图像简单方法
- vc显示jpg,gif图像简单方法
- VC下显示JPG,BMP,GIF等图像格式
- 怎样显示Jpg,bmp,Gif图像文件
- wince中显示BMP、JPG、Gif以及PNG的方法
- 在VC下显示JPEG、GIF格式图像的一种简便方法
- VC 显示jpg,gif,bmp等格式图片
- 在VC下显示JPEG、GIF格式图像的一种简便方法
- 使用IPicture的OLE实现读取和显示BMP,GIF,JPG,ICO,EMF,WMF图像
- 在VC下显示JPEG、GIF格式图像的一种简便方法
- wince中显示BMP、JPG、Gif以及PNG的方法
- VC编程之在MFC程序中显示JPG/GIF图像
- 如何在MFC中显示jpg.gif.bmp等类型的图像