Android image reading the dome of missing

Source: Internet
Author: User

Https://github.com/nostra13/Android-Universal-Image-Loader

Integrate the above source code

Resources are hard to download, about the code, there is nothing to say.

Talk about some of the problems that have been encountered during this period.

Every word of the comic is about 20 pages, which are actually JPG images, so this is about

Show the picture, but make sure that there are no oom exceptions.

Of course, Google's Android has also encapsulated a number of ways for us to do this quickly and easily, such as ImageView's Setimagebitmap,setimageresource, Bitmapfactory's Decoderesource and so on, But try not to use Setimagebitmap or Setimageresource or Bitmapfactory.decoderesource to set a large image, because these functions are finished decode, and ultimately through the Java layer of CreateBitmap. , you need to consume more memory;

Therefore, instead of using the Bitmapfactory.decodestream method first, create a bitmap, and then set it to ImageView source, load the display. Decodestream's biggest secret is that it directly calls Jni>>nativedecodeasset () to complete the decode, eliminating the need to use the Java layer's createbitmap, saving the Java layer of space

The above passage, a search on the internet everywhere.

When I use bitmapfactory.decodestream to create a bitmap and then set it as the source of ImageView , I do not report the exception. But the new problem has come again. The memory of the parsed image is small, but the picture is also compressed, showing poor results.

Later, you can use the caching mechanism to ensure that the previous page and the next page of the current page are loaded in memory to ensure smooth transitions and a bit of a queue-like pattern.

Android really provides such a mechanism-the LRUCache class, the strong reference cache.

New Lrucache<string, bitmap> (cacheSize) {               // must override this method to measure the size of the Bitmap            @Override                protectedint sizeOf (String key, Bitmap Bitmap) {                   //  Override this method to measure the size                 of each picture return bitmap.getbytecount ();              }           };
 /*** Add bitmap to memory cache *@paramKey *@paramBitmap*/     Public voidAddbitmaptomemorycache (String key, Bitmap Bitmap) {if(Getbitmapfrommemcache (key) = =NULL /*&& Bitmap! = null*/) {Mmemorycache.put (key, bitmap); }       }/*** Get a bitmap from the in-memory cache *@paramKey *@return     */     PublicBitmap Getbitmapfrommemcache (String key) {returnMmemorycache.get (key); }

class extends Asynctask<integer, Void, bitmap> {                //  loading pictures in the background.           @Override           protected Bitmap doinbackground (Integer ... params) {               final Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), params[0]);              Addbitmaptomemorycache (String.valueof (Params[0]), bitmap);            return bitmap;           }       

Really can cache, but perhaps the reason why the picture is larger, the program is running in a continuous fast switch to the next page, or here Bitmapfactory.decoderesource the oom exception.

When the last eclipse generated the signed apk, I modified the name of the item, and after the result the update reference, an exclamation point appeared.

This is because the referenced jar package path is incorrect. Right-click project name BuildPath---> Configure Build paht ... In

Then there are a few tabs above to find the package with the Red Cross in libraries as the path error package, remove and add again.

Finally with GitHub on this open source code, feel their level of real food, weak explosion.

Such as:

Resources I use PS batch compression, in order to ensure clarity, compression ratio is not small, so the installation package will be larger.

As to whether this is a benefit, if you do not want to use this program to see, you can unpack the installation package, the resources are under the assets folder.

How to unzip the apk file, I believe we all know.

Download : The Dome yearning



Other wonderful articles

Android Learning Notes ($) Android Options Menu and submenu (submenu) Android Learning note (notification) features and usage of Android learning Note (Android) using listeners to listen to menu events Android Learning notes (+) Android Create a single-selection menu and a check menuAndroid Learning Notes (Android) setting activity associated with menu itemsAndroid Learning Notes (Android context menu)

more about Android Development articles


Android image reading the dome of missing

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.