I am trying to display some images in one ImageView to obtain the functionality of slide show.
I am registering an Animation Listener to the imageview for changing each picture.
When slide show is displaying, some of the images are not visible, but its memory is allocating.
I am converting images from URL to bitmap. After doing inSampleSize = 4, I am setting the bitmap to ImageView.
Why these images are not visible? the images with below 100 Kb are visible, but with 500kb has the problem.
Thanks..
EDITED
Actually when the application launches, the images from the URL are converted to bytes and it is stored in the DB. And when we click on the Slide show button in another activity, these bytes are converted to bitmap and showed by the ImageView.
If your images are larger than a few kB, it is best practice to use a ContentProvider rather than loading these images directly from storage. This may be your problem.
http://developer.android.com/guide/topics/providers/content-providers.html#querying
Give this a read and try the ContentResolver.openInputStream and Cursor.getBlob() method of retrieving images, and see if it works any better for you.
Hope this helps!
Sorry all,
Finally I figured out the problem.
I increase the duration of animation according to image size.
Now all images are displaying fine.
Related
I want to show Thumbnails for images present on device in a GridView and I'm using getThumbnail method to get thumbnails. But for some reason when I set returned thumbnails to ImageViews in gridview, they are not clear(blurry). For example, if there's a text in an image then I'm not able to read that text in my app whereas I can read it in the native android gallery app. I hope this gives a idea of what my problem is. I think its probably because the imageview size is greater than image size.
I have tried to use methods like extractThumbnail in conjunction with BitmapFactory.Options inSampleSize but sometimes it generate OutOfMemoryException.
What should I do to resolve this issue so that the thumbnails are as clear as they appear in android native gallery application?
If I remember correctly, getThumbnail will return a scaled image. If you are then scaling that image back up to fit in your GridView, then that would account for the blurriness.
You can try scaling the images to the correct size yourself, then displaying it to the GridView.
You may also want to look at UIL. It is an awesome Open Source project that helps with Image Loading and can fix your memory issue.
In my app I have a list view, which contains an image view. The image is loaded from bas64 encoded string. First the string is decoded and then converted it to bitmap and then the bitmap is loaded to the image view.
All the decoding is done in an async task and concurrency is handled according to the below documentation.
Processing Bitmaps Off the UI Thread
The problem is the app is scrolling slow, and all other async tasks are not executing after that.
any possible solutions?
You probably insterting a huge Bitmap into a tiny ImageView like assume the image is FHD 1920x1280 and your ImageView is 192x128. You should load a smaller or same size Bitmap into ImageView. I guess this is a reason of scroll lags. Also it could be that your layout is too complex and should be optimized.
As for
async tasks are not executing after that
nobody can tell you anything without seeing your code.
If you are getting image URL from server you can store if you want to in local DB. Don't store base64 in database just store the image URL's.But for image loading you can simply use libraries that are available like Glide or Picasso for image loading. Your list view is lagging as you are doing heavy operation like decoding base64 and loading that bitmap. Just give it a try, it will work. You can load image using single line code like
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);
you might need to put images into a folder "drawable-nodpi", since normaly android app will try to resize large image first, then load it, then show show the original image(by resize again), this process will cost much CPU which make your app respond slow. So just create a "drawable-nodpi" folder as the "drawable" folder, cut/paste all large images in the new folder
My scenario:
In my activity, I have to show 2 galleries, 1 with large image and another is a thumbnail(same exactly like default Gallery application).
My doubts:
I am planning to save as 2 images(1 with large size and another one with thumbnail size) in sdcard for fast processing. Is that good practice? since it will increase the size.
Or Shall I resize the large image during the getView method of BaseAdapter to small size for displaying in thumbnail gallery?
Which one is the good practice? I don't want to slow down my app.
See this example.
I will suggest you that, put only your large image inside your sdcard. But at runtime, Android provides a good facility to get Thumbnails using MediaStore.Images.Thumbnails.
Edit:
You can also get use Loading Sample Sized Bitmap. This will first create a sample size of your requirement. Then will give you a Thumbnail sized Bitmap.
StackOverflowAnswers:
1) Get thumbnail of image on SD card
I want to load and scale an image from an URL in a imageView.
Then, when user touch that image, I want to load the image (without scale) in other imageView or webView for example.
The problem is that I don't want load image twice. The first time, it download in somewhere (cache?) and I want recover for not doing two request...
some example? suggestion?
thanks
you should consider to load first just a thumbnail of the image and wait with downloading the real one until the user really wants to see it.
for caching see LruChache
This tutorial should help with caching: http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/
If you have lots of images, consider using an LruCache. It helps manage large amounts of cache data.
I am using the following code to pick a folder from the SDCard.
Environment.getExternalStorageDirectory();
After selecting the folder, I return the path of the folder and display it in a text view currently.
What I want to do is, I want to display all images in the selected folder in the form of a slide show. How do I go about in doing this?
1. convert images in the Bitmap.
Bitmap bm = BitmapFactory.decodeFile(String pathName);
Decode a file path into a bitmap.BitmapFactory
2. Using ImageView set that Bitmap in ImageView.
ImageView.setImageBitmap(Bitmap bm);
Sets a Bitmap as the content of this ImageView.
3. For slide show just after some delay (use timer) after change the bitmap of ImageView.
We are appreciate If you are do by yourself. Without finding any code.
EDIT: Here Mihai Fonoage's Blog Displaying Images from SD Card In Android - Part 2 It display images from sdcard in Gridview. You can modified it and display Images one-by-one as a slideshow.
If all you want to do is cycle through the images one by one, there are numerous options. You could for example simply use a Timer (or preferably a ScheduledThreadPoolExecutor if you're writing production code) with a fixed interval or have a Handler repeatedly post itself with a certain delay. With each 'tick' you can then simply set the next image.
If you're after something a little more fancy, it may be worth looking at implementing an ImageSwitcher, which provides the ability to also show thumbs of upcoming/previous images. Code examples are wide spread, e.g. here (scroll down a bit).