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
Related
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
Assumes I have a picture, it very large images or other sets of content where you are only looking at small bits at a time, because you can start seeing your content without having to load it all into memory at once.
In iOs we can use CATiledLayer to repeatedly draw tiles to fill up view’s background
In Android I can see Google Map, It also load each part of map when you scroll but I don't understand what is solution of them.
I want know what is the solution same CATiledLayer in Android or other to load very large Image
you can actually scale down the bitmap according to the size of the image view.
Don't give wrap_content in width and height try to give a relative width and height.
use
ImageView.getheight()
ImageView.getWidth()
get the size and load according to it
see this link
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#read-bitmap
You can use a library load images efficiently and manage caching them instead of downloading them again. I suggest Picasso or Glide. This tutorial compares between them and explains few features.
I hope it's useful.
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
What i am trying to do is toscroll through a list of images. But when i scroll down or up quickly the images are misplaced in order. A diff pic comes in the place where it was supposed to be. I have tried setting the imageview to null drawable from my imageloader library to clear any rpevious images if any. But the issue persists. What should i do
You can try to use Universal image loader
This is for listView optimization and improving performance if your listView contain images from web.
Features:
Multithread image loading Possibility of wide tuning ImageLoader's
configuration (thread executors, downlaoder, decoder, memory and disc
cache, display image options, and others) Possibility of image
caching in memory and/or on device's file sysytem (or SD card)
Possibility to "listen" loading process Possibility to customize
every display image call with separated options Widget support
Finally discovered the culprit. I was using the imageview.bringtofront() function which was causing the problem for some unknown reason. I wanted to put a part of the imageview infront of the other and was using the relative layout & bring to front. Now i removed the bringtofront() and rearranged the imageview in relativelayout so that its already in the front. Resolved. Thank you all
i was wondering if is it efficient and possible to set 3000X2000px image as canvas background without resizing it and without getting the memory error.
because i want the real size image and pan around it.
using webview is not an option.
Currenty i tried to the set the background by using a folder structure named "Drawable-nodpi" and then assinging the bitmap image with decoderesource method.
Such a huge picture will inevitably cause outofmem exceptions on at least some devices. So I think that you need to dynamically scale and load only parts of the image that needs to be displayed, possibly with a caching mechanism.
Unfortunately, I don't know about any library components for Android that does this for you out of the box, but I'm pretty sure that you can find some nice articles on this topic.