失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Windows Mobile 上显示png jpg bmp等图片

Windows Mobile 上显示png jpg bmp等图片

时间:2020-02-06 03:47:08

相关推荐

Windows Mobile 上显示png jpg bmp等图片

不只是可以显示png,jpg,bmp等等都可以,gif也行,不过只能显示单帧。

一种方法是用IImagingFactory 中的CreateImageFromFile

先看看msdn:

This method lets an application create a decoded image object from a file.

Syntax

Parameters

filename

[in] A WCHAR array containing the name of the source file.

image

[out] A pointer to the resultingIImageinterface pointer.

Return Value

If successful, this method returns S_OK.

This method may return E_POINTER if it fails.

Remarks

When the decoded image object is created, it only keeps a reference to the external data source and does not immediately decode the image. The decoded image opens the file in read-only mode and allows shared-read access to it.

Be aware that decoded image objects are read-only. In particular, you cannot modify the image data. However, you can display it onto a destination graphics context or push its data into an image sink. For more information, seeIImage.

Requirements

OS Versions:Windows CE 5.0 and later.

Header:Imaging.h.

Link Library:Imaging.

所以很简单了

/**************************************************************************************函数名称ShowPng*函数介绍显示png图片*入口参数constWCHAR*filename,//文件路径* CRect*pRect, //显示区域* CDC*pDc, //dc*出口参数无*返回值 void************************************************************************************/voidShowPng(constWCHAR*filename,CRect*pRect,CDC*pDc){IImagingFactory*pImageFactory=NULL;IImage*pImage=NULL;HRESULThrCreInstance=CoCreateInstance(CLSID_ImagingFactory,NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void**)&pImageFactory);HRESULThrLoadFile=pImageFactory->CreateImageFromFile(filename,&pImage);if(S_OK!=hrCreInstance||S_OK!=hrLoadFile){AfxMessageBox(L"加载图片失败!!!");return;}pImage->Draw(pDc->GetSafeHdc(),pRect,NULL);pImage->Release();pImageFactory->Release();}

注意:

#include<Imaging.h>

还有另外一种方法:

就是用SHLoadImageFile函数。

先看msdn:

This function reads an image file, decompresses it, and returns a handle to a bitmap in memory.

Syntax

Parameters

pszFileName

[in] The name of the image file to be loaded.

Return Value

A handle to a bitmap if successful, NULL otherwise.

Remarks

This function converts files of several types, including GIF (Graphics Interchange Format), PNG (Portable Network Graphics), JPG (Joint Photographic Experts Group), ICO (icon), and BMP (bitmap) file formats. Other image file types may be supported if the correct decoder is installed.

When you no longer need the bitmap, call theDeleteObjectfunction to delete it.

Requirements

PocketPC:Windows Mobile and later.

OS Versions:Windows CE .NET 4.0 and later.

Header:Declared in Aygshell.h.

Library:Use Aygshell.lib.

/**************************************************************************************函数名称ShowPic*函数介绍显示png图片*入口参数constWCHAR*filename,//文件路径*CRect*pRect,//显示区域*CDC*pDc,//dc*出口参数无*返回值void************************************************************************************/voidShowPic(constWCHAR*filename,CRect*pRect,CDC*pDc){CDCdccom;dccom.CreateCompatibleDC(pDc);HBITMAPhbitmap=SHLoadImageFile(filename);CBitmap*bk,pp;bk=pp.FromHandle(hbitmap);BITMAPbitmap;bk->GetBitmap(&bitmap);CBitmap*pOldbmp=dccom.SelectObject(bk);pDc->StretchBlt(0,0,pRect->Width(),pRect->Height(),&dccom,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);}

如果觉得《Windows Mobile 上显示png jpg bmp等图片》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。