2 issues with android bitmaps - android

I have a ListView, with about 50 rows. Each item has an image. Sometimes, the images are downloaded, but sometimes, I just show a specific image from app resources.
Issues:
Sometimes I just show about 20 images from resources for my items
that all of the are the same image .it means I just show an image
for 20 rows that all the same. is it loading a bitmap an take the
amount of ram for each item ? or it just load an image and show it
for other items ?
The imageview's size for each item is 100*70 dp . so I want to do
something , like re sizing or reducing the image dp before I bitmap
them and show them in my app, so I can reduce the amount of ram they
takes . Is it possible ?
Thanks

Showing same image multiple times
If you set all the image as same Drawable (variable), you got from resources, Only 1 bitmap Drawable resides in RAM. Also, ListView recycles its rows, it does not really create 20 rows with all 20 Bitmaps loaded in RAM.
Setting DPI of images
BitmapDrawable class can automatically decide DPI for rendering, that's why it asks for Resources in its constructor. Or you can call setTargetDensity(int) later. NOTE: Changing DPI is not exactly same thing as Scaling an Image.
Loading scaled down images
This will definitely save RAM, Read Answers on how to load scaled down images.

Related

Android : Assigning a high resolution image to a smaller ImageView

I have this unanswered question of mine pertaining to images. I have an image of about 1 MB and I am assigning the images to an image view with width and height of 100dp and 80dp respectively. But when I assign the image to about 5 image views, the application crashes with Out of Memory Error
So, when I assign the 1 MB image to such a small image view, what happens? Doesn't android scale it down? Also, did the app crash because it couldn't take the load of 5MB in memory??
EDIT
I have 5 ImageViews on the screen. I am assigning the image to all if them this way
myImageView.setImageURI(item.getImageUri());
Android loads the whole image file to the memory and then scales it down. In order to avoid OOM you should load large bitmaps efficiently.

Android Gallery Loading a lot of images from local makes scroll not smooth

I am using the android Gallery widget loading images from Bitmap[] succesfully, but it seemms the scroll is not very smooth. Initial conditions:
Image resources comes from a local array of Bitmap (previously full filled)
If i load only three images, it seems going smoother
The size of each individual item is light weighted Bitmap (less than 30KB)
The dimensions of each individual item is like 200x350 px
What could i do to optimize it ?
Thx in advance!!

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

ListView items. Handle images with huge height

I have listview items with simple View inside, and i need to display image with huge height in it. I have cache system which can split large image into smaller ones.
Question:
What is the best way to handle displaying large images in one listview item?
Sure i can add some views to item at runtime(10 view 1000px height for example), but i think that i will get out of memory.
My point is to make my app display image like 9gag app.
9gag app
9gag view hierarchy
Do not load large bitmaps to memory consider loading a smaller version into memory, set inSampleSize to true in your BitmapFactory.Options object. For example, an image with resolution 2048x1536 that is decoded with an inSampleSize of 4 produces a bitmap of approximately 512x384.
Use these common guidelines for loading large bitmaps

Android ListView image resize

I have a lazy-loading ListView populated with images gotten over the network. The list rows are set to wrap_content, so once the image loads it resizes and the full scale image will be displayed. It looks great when scrolling down, but when scrolling up the rows resize and force the bottom rows off the screen. How can I prevent this jumpy scrolling while scrolling up?
----- EDIT:
The images are comics of varying sizes. Some are 2 or 3 frames where they aren't very tall. Others are single frame comics where they are much taller. The image needs to take up the full width and the height should not cut off any of the comic.
Assuming all images downloaded are expected to be around the same size, a good solution most developers use is to use a "dummy" image until the real image is loaded. This image will exist locally so it can be loaded almost instantaneously. In the getView method, show this dummy image until the real image is downloaded, and then simply replace it. This will prevent your rows from resizing.
you have to see this link It downloads images in the background thread. Images are being cached on SD card and in memory, It decode images with inSampleSize to reduce memory consumption and also try to handle recycled views correctly. Play a fake image when image are not completely downloaded. "sorry fo the music!!"
I figured out the solution. When I receive the image, I get the width from the parent then set the height of the image view to parentWidth * bitmapHeight / bitmapWidth. That way the resizing occurs as the row's view is created and the list doesn't jump around as much once I know the size of the bitmap.

Categories

Resources