Windows Mobile displays PNG, JPG, BMP, and other images

Source: Internet
Author: User

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.

  1. /*************************************** **************************************** *****
  2. *
  3. * Function name showpng
  4. * Function Introduction: Display PNG Images
  5. * Entry parameter const wchar * filename, // file path
  6. * Crect * prect, // display area
  7. * CDC * PDC, // dc
  8. * No Exit Parameter
  9. * Return value void
  10. *
  11. **************************************** **************************************** ***/
  12. Void showpng (const wchar * filename, crect * prect, CDC * PDC)
  13. {
  14. Iimagingfactory * pimagefactory = NULL;
  15. Iimage * pimage = NULL;
  16. Hresult hrcreinstance = cocreateinstance (clsid_imagingfactory, null, clsctx_inproc_server, iid_iimagingfactory, (void **) & pimagefactory );
  17. Hresult hrloadfile = pimagefactory-> createimagefromfile (filename, & pimage );
  18. If (s_ OK! = Hrcreinstance | s_ OK! = Hrloadfile)
  19. {
  20. Afxmessagebox (L "failed to load the image !!! ");
  21. Return;
  22. }
  23. Pimage-> draw (PDC-> getsafehdc (), prect, null );
  24. Pimage-> release ();
  25. Pimagefactory-> release ();
  26. }

Note:

  1. # 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.

 

  1. /*************************************** **************************************** *****
  2. *
  3. * Function name showpic
  4. * Function Introduction: Display PNG Images
  5. * Entry parameter const wchar * filename, // file path
  6. * Crect * prect, // display area
  7. * CDC * PDC, // dc
  8. * No Exit Parameter
  9. * Return value void
  10. *
  11. **************************************** **************************************** ***/
  12. Void showpic (const wchar * filename, crect * prect, CDC * PDC)
  13. {
  14. CDC dccom;
  15. Dccom. createcompatibledc (PDC );
  16. Hbitmap = shloadimagefile (filename );
  17. Cbitmap * BK, pp;
  18. BK = pp. fromhandle (hbitmap );
  19. Bitmap bitmap;
  20. BK-> getbitmap (& Bitmap );
  21. Cbitmap * poldbmp = dccom. SelectObject (BK );
  22. PDC-> stretchblt (0, 0, prect-> width (), prect-> height (), & dccom, 0, bitmap. bmwidth, bitmap. bmheight, srccopy );
  23. }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.