You can not only display PNG, JPG, BMP, etc., but only display a single frame.
One way is to use createimagefromfile in iimagingfactory
Let's take a look at msdn:
This method lets an application create a decoded image object from a file.
Syntax
|
HRESULT CreateImageFromFile( const WCHAR* filename, IImage** image); |
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 particle, 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.
So it's easy.
- /*************************************** **************************************** *****
- *
- * Function name showpng
- * Function Introduction: Display PNG Images
- * Entry parameter const wchar * filename, // file path
- * Crect * prect, // display area
- * CDC * PDC, // dc
- * No Exit Parameter
- * Return value void
- *
- **************************************** **************************************** ***/
- Void showpng (const wchar * filename, crect * prect, CDC * PDC)
- {
- Iimagingfactory * pimagefactory = NULL;
- Iimage * pimage = NULL;
- Hresult hrcreinstance = cocreateinstance (clsid_imagingfactory, null, clsctx_inproc_server, iid_iimagingfactory, (void **) & pimagefactory );
- Hresult hrloadfile = pimagefactory-> createimagefromfile (filename, & pimage );
- If (s_ OK! = Hrcreinstance | s_ OK! = Hrloadfile)
- {
- Afxmessagebox (L "failed to load the image !!! ");
- Return;
- }
- Pimage-> draw (PDC-> getsafehdc (), prect, null );
- Pimage-> release ();
- Pimagefactory-> release ();
- }
Note:
- # Include <imaging. h>
There is another method:
The shloadimagefile function is used.
First look at msdn:
This function reads an image file, decompresses it, and returns a handle to a bitmap in memory.
Syntax
|
HBITMAP SHLoadImageFile ( LPCTSTR pszFileName); |
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, callDeleteobjectFunction to delete it.
Requirements
Pocket PC:Windows Mobile 2003 and later.
OS versions:Windows CE. Net 4.0 and later.
Header:Declared in aygshell. h.
Library:Use aygshell. Lib.
- /*************************************** **************************************** *****
- *
- * Function name showpic
- * Function Introduction: Display PNG Images
- * Entry parameter const wchar * filename, // file path
- * Crect * prect, // display area
- * CDC * PDC, // dc
- * No Exit Parameter
- * Return value void
- *
- **************************************** **************************************** ***/
- Void showpic (const wchar * filename, crect * prect, CDC * PDC)
- {
- CDC dccom;
- Dccom. createcompatibledc (PDC );
- Hbitmap = shloadimagefile (filename );
- Cbitmap * BK, pp;
- BK = pp. fromhandle (hbitmap );
- Bitmap bitmap;
- BK-> getbitmap (& Bitmap );
- Cbitmap * poldbmp = dccom. SelectObject (BK );
- PDC-> stretchblt (0, 0, prect-> width (), prect-> height (), & dccom, 0, bitmap. bmwidth, bitmap. bmheight, srccopy );
- }