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
The yearning of the dome