I have full-sized image files stored on the phone's filesystem, and a method for loading a thumbnail version to be used in a ListView. I basically use the sub-sampling technique that is discussed often on SO and also here.
The method outlined in the link requires you to provide a target width and height in pixels for the sub-sampling to work. For my list view, this is fine because the thumbnail width/height are defined as dimension resources, and are easily converted to pixels. The ImageView that these are loaded into use a scaleXY scale type.
In addition to the list view, I have a separate detailed view where I want to display the selected image as a banner at the top of the screeen, but using a scale type of center (no resizing). The target ImageView is within a RelativeLayout with a fixed height (set in the resources area), and the width set to fill_parent.
So I have 3 questions:
Given that I don't want any special resizing done on the banner image (scaleType is set to center), is the sub-sampling technique still applicable here?
If the answer to #1 is yes, then I would need to be able to calculate the target view's width. Since the width (unlike the height) of the target ImageView isn't fixed like the thumbnail view, how can I find what the effective width the fill_parent ends up as?
If the answer to #1 is no, then how can I efficiently load this image into the view without risking a memory exception?
Thanks!
Related
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 am developing an android application using Google app engine.We have custom list view in which image has to be shown. I have used lazy loading for list view to load more data on demand.But problem is here, I am getting images from server, User can upload images of any size. Being used such images by user, I am not able to manage height and width for every image in list view List view is looking very ugly. How can I manage such images in specific height and width in image view?
Please share your best answer.
Thanks,
Prashant.
You can use the Google Images API for this. It has the capability to resize images have a look at
https://cloud.google.com/appengine/docs/java/images/
Using this you can
Resize
Rotate
Flip horizontally
Flip vertically
Crop
any image at runtime
Now when fetching the images use resize to scale down images to a specific dimension and use it in your listview
Simply there are 2 options.
Use android's ImageView.ScaleType
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
ImageView iv = someView;
iv.setScaleType(CENTER_CROP) // also CENTER_INSIDE, CENTER, whatever you want.
or in xml
<ImageView
...
android:scaleType="center" />
use blobstore magic url
https://cloud.google.com/appengine/docs/python/images/functions#Image_get_serving_url
How to display an image using a URL of a known jpg, png ..etc. File ?
I want an image , and I want it to be loaded from the internet from a particular website.
With that done,
I would like to make that image of an appropriate size...
Say I put the width as the same as screen_width (size)....What about the height ? I don't want to spoil the ratio of height/width of the original image...So is the height automatically set to account for the ratio ? or do I have to put in some value myself ...?
Plus, I want it to be zoomable.
To load images from website, you need to get the path from website server where the photo is stored. For image displaying put height as wrap_content mode so that the space will occupy as much as needed to display.
For this purpose you can use a Lazy Adapter. Here you can find a good example of it: https://stackoverflow.com/a/3068012/2436683. Maybe you can use it as a starting point.
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.
I want to create a list with some text and a photo miniature in each row.
So I created a row layout with a TextView and a ImageView, my question is how do I make the ImageView just a little square and then make an image adapt to the size of the ImageView?
<ImageView .... android:scaleType="centerInside" />
Set full screen image as an image resource of this image view. It will be downscaled automatically.
Additionally you can limit width and height setting android:maxWidth and android:maxHeight attributes to prevent minature to be too large.
my recommendation is you do not scale the image to fit the view as this is an expensive operation and will slow down your app it is preferable to prescale the item to the size you want.
Take a look at this Strange out of memory issue while loading an image to a Bitmap object. It's a correct way to get miniature with minimum memory consumption.