如何用c语言 加载和显示png图片,谁能详细说下,呵呵

jingricj 2010-03-15 03:19:26
RT
...全文
598 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wltg2001 2010-03-15
  • 打赏
  • 举报
回复
如果不想用GDI+的话,用IPicture接口也可以,代码如下:
::CoInitialize(NULL); // COM 初始化
HRESULT hr;
CFile file;

file.Open( "c:\\aa.jpg", CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容
DWORD dwSize = file.GetLength();
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
LPVOID lpBuf = ::GlobalLock( hMem );
file.ReadHuge( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
IStream * pStream = NULL;
IPicture * pPicture = NULL;
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
ASSERT ( SUCCEEDED(hr) );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
ASSERT(hr==S_OK);

long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高

////////原大显示//////
CSize sz( nWidth, nHeight );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
pPicture->Render(pDC->m_hDC,0,0,sz.cx,sz.cy,
0,nHeight,nWidth,-nHeight,NULL);

////////按窗口尺寸显示////////
// CRect rect; GetClientRect(&rect);
// pPicture->Render(pDC->m_hDC,0,0,rect.Width(),rect.Height(),
// 0,nHeight,nWidth,-nHeight,NULL);
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem

::CoUninitialize();
feilongjilei 2010-03-15
  • 打赏
  • 举报
回复
GDI+:
Graphics graphics(hdc);
Image image(TEXT("1.png"));
graphics.DrawImage(&image, Rect(x1, y1, x2, y2), 0, 0, image.GetWidht(), image.GetHeight(), UnixPixel);
包含声明:
#include <gdiplus.h>
using namespace Gdiplus;
再加上初始化 和结束 GDI+ 的函数
GdiplusStartup() GdiplusShutDown()
吧!
当然还可以用各种界面库中的函数了,哈哈!
wykqhyjs 2010-03-15
  • 打赏
  • 举报
回复
DING ,具体呢
Eleven 2010-03-15
  • 打赏
  • 举报
回复
GDI+加载png图片。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧