I am really trying to figure out which is the best way of loading a huge image in Android ImageView( or some other view extending ImageView).
I am aware of OOM issues with Android framework when working with bitmaps but still I need to implement the following requests:
horizontal scrollable imageview
must load a huge 8000px (keeping original image quality so no downsample) width and device height png image from drawble-nodpi in it and to be fluent while scrolling it without preloads or lag(recyclerview will have blinks so it is a no go I tried that)
I am thinking at a customview extending imageview and something to decode only current scrolled region from that bitmap but I am stuck here
avoid oom
also does a pdf viewer library be better than using huge png from performance point of view? I need the picture preloaded on app start not lazy loaded
Related
suppose that I have just one ImageView inside a HorizontalScrollView. The problem I'm facing is I have to create a very wide Bitmap to place it inside my ImageView and, obviously, use the scroll from HSV to see all my image there. I'm getting a lot of OutOfMemoryException so, is there any technique to get this task done without getting a ton of OutOfMemoryExceptions?
You are getting OutOfMemoeryException because your bitmap is too large to load the entire bitmap into memory (a loading issue not a rendering issue).
Instead you need a custom image view that downsamples and/or only loads sections of the image at a time depending upon what part of the image should be currently visible.
This may not fit your use case but it is an example of this problem being solved by downsampling
I've been trying to create a Recycler View full of Card Views. Currently, I'm using the Recycler View from this tutorial and loading it with 14 different images. The professional quality images range in size from 134K to 242K.(Down from 8MB - 18MB)
I know that the images may be too big but, I feel there must be some way to get better performance while scrolling. Can someone point me in the right direction?
Edit: The images will be stored on the device. There will probably never be more than 20 of them.
You can use Picasso library or Android Universal Image Loader
Picasso
Android-Universal-Image-Loader
You don't need any AsyncTask.Theese 2 library handling image operations in background so you can keep scrolling smoothly. I am using Picasso in my project right now. You can add error drawable , temporary placeholder default drawable , and its so simple automatically caching.
Just use one of them in onBindViewHolder to bind any image to imageView
Load the images in a separate thread (or AsyncTask).
I know that ,according to android docs, that if you have a big image. Then you scale it down to size of the image view you are loading it to (using the decodeResources and Options class).
Now my question is, lets say you want to load background picture and the source image is of similar size, do you just load the image? Or do you actually scale it down a bit and then using the FITXY to stretch it?
I am trying to avoid Out Of Memory exceptions here
Thank you
I mean, that the TextViews loads almost at once, however the ImageViews loads a bit slower, and this looks very ugly, and disturbing.
What can I do against it?
I load the images of the ImageView on the fly, and set the images of the ImageViews with setImageBitmap() in a background process.
setImageBitmap is time-consuming - it requires loading bitmap data from storage, memory allocation, decoding, etc, etc. A TextView obviously needs to do no such thing.
You can improve the situation somewhat by using placeholder images of the same size as the image that you're about to load, using transition animations, or (whenever possible) using resource drawables.
I'm currently downloading a bunch of thumbnails in memory as a bitmap, resizing the bitmap via Bitmap.createScaledBitmap, and then using the resized bitMap to populate a BitmapDrawable, which I subsequently load into an ImageView to display.
As you can imagine, with a couple of dozen images this can be quite slow. Does anyone have any suggestions on how I can speed this up? I've tried resizing the Drawable via .setBounds, but that doesn't seem to work.
edit I am loading the bitmap into a drawable because at some future point I wish to utilize layers to add some text overlays to the image prior to display