Summary of UIImage related development experience in iOS

Source: Internet
Author: User

iOS and UIImage related functions for a period of time, here to summarize the relevant experience.

1. Basic Frame Image IO

Image io can generate cgimagesourceref from a URL or data provider, and can then get the first few pictures or thumbnails on source, based on http://www.mindsea.com/2012/12/ In downscaling-huge-alassets-without-fear-of-sigkill/, using this method is more than loading the fullsolutionimage directly, and then using the core graphics processing to consume less memory , which I have not clearly found out.

In addition, image IO can be a gradual display of images, which means that the image can be gradually decompressed.

Image IO can also export pictures, Cgimagedestinationaddimage method can set the content and image related properties, such as Exif, GPS and other properties, These properties are in fact the metadata attribute in Alassetrepresentation, and the Http://zacwe.st/blog/saving-jpegs gives a separate useUIImageJPEGRepresentation和image IO导出图片的比较,image IO相对UIImageJPEGRepresentation节省的比例和我测试差不多,2000*2000的图平均在20%左右,但时间没有那么大差距,基本上接近,最多10%的差距,有时候image IO反而更少。

There are several main issues in exporting a picture, the UIImageJPEGRepresentation method does not export the picture's metadata, and the image IO export does not have a color profile, which is why the image IO version is smaller. UIImageJPEGRepresentation Way will lose EXIF and other information, one way is to add back through image io, one is to read the image of the binary, their own manual write bytes, this is generally the use of open source software, more trouble and easy to discard information, not recommended to use. Image io This seems to be the best, but I found a comparison of the problem of egg pain, and so on to the application server, the service side once again to do the processing, actually more than the uiimagejpegrepresentation produced, it is more strange, need to analyze the implementation of the service side.

2. UIImage's display

UIImage shows the performance aspect of the list, which is a heavier component. Personally think the main impact of CPU consumption, memory consumption, GPU aspects of the main guarantee not to appear blending on it; take Uiimageview display as an example:

A. Uiimageview does not use Backingstore, but uses cgimageref as the content of the Calayer. (Here cgimageref should be in RAM memory)

B. Commit changes via Catransaction, in the next runloop, allocate memory, read files, decompress, form bitmap to the GPU

in Fic, when it comes to iOS 7 picture hardware decompression is not open to third parties, but personally think that if the GPU decompression, unzip the good picture is best able to cache, or there may be repeated decompression situation. Therefore, it is usually asynchronous to load and decompress, and then drop to Uiimageview to do the display. In some low-end devices, it is possible for an asynchronous thread to do another drawinrect (the person thinks it handles such things as dimension stretching, byte alignment, etc.), so that the memory will be more expensive, but more efficient.

Therefore, in the FIC put forward a targeted solution, it is stored like a sprite Sheets,io file opened only once, directly store the extracted data, but also do byte alignment, CA do byte-aligned copy, My personal understanding is to ensure that GPU rendering does not require additional data completion for bitmap, because it is neat to move, part-redraw, and so on, without additional processing, mmap reduces the copy work of the memory (at least kernel to ram) and uses VMS It is helpful for memory use, but mmap generally speaking, it is efficient for large documents, and the efficiency of small fragmented files is rather bad.

The defect of FIC is that it is relatively suitable for small files of the same size, if the file is larger, the uncompressed data occupies a larger space. The application of the scene is not common, the current irregular large picture, or use Calayer way to deal with, auxiliary control display timing and drawinrect, and other ways.

3. Picture format

JPG and GIF are current mainstream formats, but there are also alternatives. Quote a piece of know-how: "The Mozilla community is advocating APNG with animations .... Chrome has its own WebP format, and animated WebP is an animated WebP that includes a true (8bit) alpha channel, each frame can be set to be lossy or lossless as needed, and GIF is only 1bit, The size of the GIF file can be compressed even smaller.  ... As a result, GIF has not been replaced by the new format of the community for their respective interests of the outcome of the stalemate, and eventually will be gradually replaced. ”。 Now there is a MP4 format instead of GIF, really bitter program ape.

Do not know who has the practical application of WEBP, there is no immediate feeling.

4. Image upload

Upload the focus of the image is the upload method, the current understanding is the sub-block upload, communication using socket/http/http pipeline, etc., the efficiency of the best should be the direct use of the socket, but control the trouble point; HTTP is the most traffic, time is the longest In the case of better network situation, these ways are not very different; in the case of poor network conditions, the socket and HTTP pipeline duplex should be better.

5. Image processing

Personal inclination image processing client to do the processing effect of the display map, the server to do the real picture processing; Save the resources of the client, not the filter mirror and other technologies, I basically have no experience, IOS 7 is a lot of filter features, but this piece of customization is stronger.

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.