Three methods for using PNG images in Mobile

Source: Internet
Author: User
Tags transparent color

N I have never written a blog for a long time. The main reason is that people are too lazy to play games when they have time ......

But this time, I made up my mind to write it once a week. One is to record the changes in life and technological advances in a week.

I have been working for three months. After I got to work at the company, I mainly engaged in mobile development, because I had learned windows programming before. Although it was quite a level, I had a thought, therefore, it is faster to get started.

This week, I mainly work on the desktop plug-in on the Mobile, which is similar to the quickclock plug-in. However, due to the level too many times, I spent two days working on PNG images, it has not been fully clarified yet.

There are not a few methods to use PNG images on mobile, but I knew there was a libpng library on Monday, and then I looked for an example to see how to use it, I want to use the libpng library to load PNG images.

Libpng is an open-source PNG decoding library and has the corresponding mobile version. To load and use it, you must know two very important structures in it. One is png_structp, and the other is png_infop.

Png_structp is the image structure pointer, and png_infop is the information pointer. They are defined in PNG. h. Using the png_create_read_struct function, the png_structp structure pointer is returned after the execution is successful, which also contains various information about the image. Then you can set png_ptr-> io_ptr and assign the file pointer of the PNG Image to it. I don't know what is going on, huh, huh. Call png_read_png to decode the entire image. However, you can also perform a row-by-row solution with functions such as png_read_row.

The last read data must be converted before it can be used, because I am also confused to read it, so it is not in-depth. Now I only know a rough idea.

However, if you want to simply use a PNG image, for example, you only need a PNG image, but you do not want to use its transparent color or the like, use shloadimagefile directly. This function is very useful. This may be proprietary to mobile. I don't know if it can be used on the PC.

Another way is to use the iimage interface. This method is very useful, but because it is used to draw on the Target DC, every time it is painted, every time it is decoded, so if you want to make an animation, the speed may not root.

Because it is easy to use, just paste its code:

  1. Iimagingfactory * pimgfactory = NULL;
  2. Iimage * pimage = NULL;
  3. HDC = getwindowdc (hwnd );
  4. Coinitializeex (null, coinit_multithreaded );
  5. // Create the imaging factory.
  6. If (succeeded (cocreateinstance (clsid_imagingfactory,
  7. Null,
  8. Clsctx_inproc_server,
  9. Iid_iimagingfactory,
  10. (Void **) & pimgfactory )))
  11. {
  12. // Load the image from the JPG file.
  13. If (succeeded (pimgfactory-> createimagefromfile (
  14. Text ("// image.png "),
  15. & Pimage )))
  16. {
  17. // Write image data to g_hbkdc
  18. Rect rcbmp = {0, 0, width, height };
  19. Pimage-> draw (HDC, & rcbmp, null );
  20. Pimage-> release ();
  21. }
  22. Pimgfactory-> release ();
  23. }
  24. Couninitialize ();

I still want to see TAPI this week. It's just Friday. Alas, it's only next week ......

 

(I'm a cainiao, and there may be many mistakes above. I hope you can criticize and correct them. I still have a lot of mistakes to make and edit them ......)

 

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.