您的位置:首页 > 编程语言 > C语言/C++

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
...{


if (!m_spIPicture)


return CSize(0,0);




LONG hmWidth, hmHeight; // HIMETRIC units


m_spIPicture->get_Width(&hmWidth);


m_spIPicture->get_Height(&hmHeight);


CSize sz(hmWidth,hmHeight);




if (pDC==NULL) ...{


CWindowDC dc(NULL);


dc.HIMETRICtoDP(&sz); // convert to pixels




} else ...{


pDC->HIMETRICtoDP(&sz);


}


return sz;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: