Android Bitmap Open Source image frame Analysis (Essence four)

Source: Internet
Author: User

Disk Cache
The main difficulty is in memory cache, disk cache is actually relatively simple, that is, the picture is loaded after the picture file saved to the local convenient next use


Similarly, the introduction of the official homepage (homepage address at the beginning of the article)
Similar to the memory cache, several categories are available depending on the algorithm, and can be self-imageloaderconfiguration.disccache (..) Set up
<ignore_js_op>



Hard disk cache, saved in the form of a file
Framework provides 4 types, specific algorithm rules are different, look at the name we can probably know the corresponding meaning


Unlimiteddisccache does not limit the cache pool size, the fastest disk cache, the default hard disk cache mode (30% faster than other disk caches)
Totalsizelimiteddisccache limits the total size of the cache pool, deleting the oldest saved picture cache file when it is exceeded
Filecountlimiteddisccache limit the total number of cache pools, when deleting the oldest saved picture cache file, when the cached picture is the same size as when using this disk cache type
Limitedagedisccache does not limit the size of the cache pool, only limits the file save time, if the picture file is deleted when it exceeds the defined time


Similarly, specific algorithms are not discussed ~


The picture cache file location is the Android\data\ app package name \cache folder that is first saved under the memory card
(No permissions, no SD, etc. can not be saved to the SD card case, then saved in the phone memory data\data\ app package name \cache folder)
As you can see, the file cache is saved in a separate application, each app sets a cache folder, and the name of the image file is MD5 encoded.
<ignore_js_op>



--------------------------------------------------------------------------------------------------------


The picture loads some specific numeric settings
More important, such as limiting the width of the picture is appropriate AH ~ Cache pool Size Limit how much ah, and so on ~
UIL in the framework is set in the basic Configuration object, as mentioned earlier, there is a default setting Imageloaderconfiguration.createdefault (this);
For most of the situation is applicable, to modify some of the commonly used configuration, the Setup method can go to GitHub UIL Homepage Download (the article at the beginning of the address, the end of the article I will also add the attachment) compression package, including the source code and sample code, You can view some common basic configuration settings and display configuration settings in the sample demo


Here are just a few important value settings


Limited width and high value after image compression
<ignore_js_op>

Different limit values are set, there is a priority ~ I studied the next (actual measured width and height is not too clear)
Priority memorycacheextraopstion > Width/height > Maxwidth/maxheight > Divice screen

That is, from high to low traversal can get to the value, obtained as a limited width high value after parsing compressed picture instance object



Settings for cache pool Size ~
Strong references and weak references, weak references We know we don't have to limit ~ primarily for strongly referencing partial cache pool restrictions
Tutorial (ii) also mentioned, there are two main types: Limit the total number of pictures and limit the amount of memory of all the pictures
For the qualification of strong reference size, we look at the default handling of the UIL framework

[mw_shl_code=java,true]/**
* Creates default implementation of {@link MemoryCache}-{@link lrumemorycache}<br/>
* Default Cache size = 1/8 of available app memory.
*/
public static memorycache Creatememorycache (int memorycachesize) {
if (memorycachesize = = 0) {
memorycachesize = (int) (Runtime. GetRuntime (). MaxMemory ()/8);
}
return new Lrumemorycache (memorycachesize);
}[/mw_shl_code] gets 1/8 of the available memory of the program as the cache pool size, is also the recommended setting, there is a need to call the above method to pass in the >0 custom size value can be set to limit the total number of pictures, I do not look at the eyes of the default settings are not found in the source code, After all, set the memory size more appropriate if you have special needs in your project, you can refer to the relevant sections in the tutorial (ii) to set up in addition to the disk cache pool, because the default is the unlimited disk cache type, there are no specific parameters of the value of the set up ~ and the number of picture download thread problem, Disk image naming problems and so on, not the core-the space is limited here is not introduced------------------------------------------------------------------------------- -------------------------


Above, the core code analysis of the end ~ have been understood, the image processing has been considered small has become, the benefits of it ~
On the one hand, when using the framework you can better understand the internal mechanism, the appropriate time according to the specific needs of the project to do the relevant inheritance rewrite to modify (preferably do not directly modify the open source framework source code, to ensure its integrity)
On the other hand can be regarded as one of their own advantages points, especially in the interview more play ~ such as introduction of their own projects, most of the network data interaction projects are generally there will be a list of multi-image loading situation, you can load some of the picture on the part of the big talk ~ But talk about the framework part of the risk, For this lack of knowledge of the interviewer, sometimes unclear is not necessarily aware of the calendar, will be wasted saliva ~ best combination of Project side of the demonstration side, specific skills here is not swim, you can find some posts online to see




The following is also optional viewing
Includes some of the extension functions of the UIL framework, as well as the source


--------------------------------------------------------------------------------------------------------


UIL framework in the core of image caching technology, picture compression, asynchronous threading download picture of traditional frame function outside ~
And did some of the other
Expansion capabilities
Custom ImageView control, called Imageaware, supports features such as rounded corners
Disk Save picture file name MD5 encoding
Image loading display effect, such as fade-in fade effect, etc.
(There are also some extended features that are not described in detail because of non-core parts)
Besides, it also provides widget~, which I didn't study.


SOURCE structure
Mainly divided into three big bags ~ below to introduce


UIL Cache Pool Partial Package/class structure
See, it is clear that the structure of the cache buffer package is divided into two parts, disc (disk cache) package and memory cache package
The green part is the base class parent ~ Impl is a specific implementation subclass, such as the memory of the Impl package of the 8, is we previously described can be directly used by the different cache pool type, the project has special needs, you can also customize a class inheritance rewrite to make corresponding changes
Disk Similarly, base class + concrete implementation class, on this basis more than a naming named package, is the picture to save the file name for MD5 encoding and decoding processing

<ignore_js_op>







Core Package
Which focuses on the red-framed part
Picture Resolution package Decode
Basic Configuration Class Imageloadercofiguration
Display Configuration Class Displayimageoptions
And the most important picture loader class Imageloder
Other parts
Assist is the helper package, most of which are enum enum classes, such as the previously mentioned image scaling type, image compression type, etc.
Display picture shows the package, the frame provides a picture of the rounded rectangle, and the fade effect (from transparent to solid) when loading the picture.
Download Picture download package, limited Space this feature does not do analysis here
Imageaware Custom Picture control package, provide rounded effect, etc.
Listener Monitor package, the picture starts loading, loading, loading and so on monitoring
Process package, you can inherit the inside of the interface to define the effect of the image loading process
There are some other threads ah, the default configuration file generation class Ah, and so on, the same space limited do not do analysis
<ignore_js_op>







Tool Pack
Provide some required functions, such as IO stream processing, disk cache path processing, etc.
One of the most important is the picture shown in the Red box size tool class, such as the previously mentioned Computeimagesamplesize calculation scale is in this class
<ignore_js_op>





--------------------------------------------------------------------------------------------------------


Finish


Wrote about nearly a week, modified time accounted for more than half, repeated changes, but also because of limited personal skills, part of the posture is also the side of the research writing, there may be less detailed or wrong place again hope that we put forward, a lot of correction or joint discussion, but also hope that we can collect a bit, I will also continue to polish or supplement the article in the short place


UIL powerful is undoubtedly, the code framework is also very clear, the document is also complete ~ but for developers, especially me, beginners a little bit down or very difficult, it is best to look at tutorial one or two, fully understand the later read this article, of course, twos understand the basic piece processing is almost


This is equivalent to a previous tutorial to verify that "you see, the most well-known framework is basically the same way to deal with it ~" and so from the side to confirm the tutorial method of the Reliable ~

What about other roles? Through the study is certainly to improve our technology, learning other people's class structure design ~ also can better use the picture frame (the other framework is almost the same logic), and for the expansion of the part can also be used as their highlight in the interview ~

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.