Loading images into big size imageviews - android

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

Related

ImageView image size

As far as I know, if image is too big, it can't be displayed in some fixed size ImageView. My question is how can I find out maximum size of image that can be displayed if I know width and height of ImageView.
Android can display bitmaps up to 2048x2048 pixels. It dependents on OpenGL implementation.
But the main issue with big images is a insufficient memory problem. Big images takes more memory and leads to OutOfMemoryError and app crash.
The best way is scale image before displaying to ImageView size. There is a lot of image loading frameworks that can help you. For example Fresco, Glide

Load a very large Image in android

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.

Scaling image without losing quality

Is it possible to scale image without loosing its quality?I have seen posts that say to use Ninepatch images but how can we download an image and convert it to ninepatch image so that i can show it in ImageView.
Is there any other way so that my images with smaller size can be scaled like in whats app
Everytime you scale an image it's losing quality, the only thing you can do to keep the quality is keeping a copy of the original image (which doesn't make much sense since you can just load it again from resources).
If you mean the problem was that android was scaling your images (and changing the quality) you can put images on a folder named "raw" inside res.
Ninepatch images can be made manually by you, you just paint an image that has two extra pixels on width and two on height, and when you save it , name it something.9.png
if you want to know how to draw them correctly follow this: http://developer.android.com/tools/help/draw9patch.html

Draw a big image in center_crop type

I have a big image(about 2Mb 1024 * 540 ARGB8888) which is got via net. This image will be shown in a ImageView which is 800px width and 400px height in CENTER_CROP scale type. And there are 12 this kind of ImageView in a listview.
My question is:
Does android load the whole image into memory in CENTER_CROP mode cause it is very slow when I slide the listview. Maybe I should clip the image before setImageBitmap()? Which is the efficient way?
Read the information from the link bellow. It will help you better to understand how to work with bitmaps in android and even in ListView. You should cash images so you will not download them anytime the ListView is refreshing.And yes,android loads all the image and after that centers it and crops,what you should do is to load in memory only a thumbnail of the all image and display it and not all the image. And as i wrote, you should cash them.
Android Bitmap managing

difference between setting imageView smaller vs scaling image itself

I guess this question could be applied to both iphone and and android.
When I want to show smaller image,
I can set imageView to smaller size and let iphone handle the resizing to fit in the view.
Or
I can actually resize the image itself.(using opengl call, or such as wrapper call createScaledBitmap in android)
I find option 1 is faster.
I always wondered why?
I also wondered the memory consumed by the image is governed by the size of imageView or image?
This is good question, I think when we resize the imageView to smaller that And image(UIImage) is greater that time memory consumption is more because of that image (UIImage) size is more respect to display in imageView. I think second option would be good to save memory .
Image resizing need extra CPU cycles.So Its better to manually resize the image.

Categories

Resources