views:

1529

answers:

6

Currently we have a Gallery view to which we need to add thumbnails for images/video. How do we get the already generated thumbnails (the ones that the native Gallery app shows) if we already have the image's/video's content:// URI?

(We are using Android 1.6, Video.Thumbnails does not exist)

A: 

If I understand correctly, you have images and videos served by content provider and accessible as URIs. You want to create thumbnails for such images and videos.

I don't know how to do this with video files, but this is how I will implement it with image files.

  1. Open the image as InputStream using ContentResolver's openInputStream method. http://developer.android.com/reference/android/content/ContentResolver.html#openInputStream%28android.net.Uri%29

  2. Create a BitmapDrawable with the above InputStream using this method http://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html#BitmapDrawable%28android.content.res.Resources,%20java.io.InputStream%29

  3. Scale down the BitmapDrawable to desired width and height of thumbnail. Follow this tutorial. http://www.anddev.org/resize%5Fand%5Frotate%5Fimage%5F-%5Fexample-t621.html

  4. [Optional] You may want to cache the thumbnail, so that you don't have to repeat above steps everytime the user accesses your Gallery.

Jayesh
+1  A: 

Here you go.. working very nicely....! http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html

Hrushikesh
A: 

I think for Images, the answers above could be useful. For videos, the class MediaMetadataRetriever is what is used by the native Gallery app., but unfortunately, that is not a published API.

A: 

@Jayesh

When you say cache the thumbnails, what exactly do you mean ? How and where can one cache thumbnails ? The thumbnails for images already exists on the sdcard so won't that be creating another copy of the same thumbnails ?

Tee
A: 

Please find the solution at my blog: http://sadeqbillah.wordpress.com/2010/09/20/showing-video-thumbnails-in-android-2-0/. However this is for 2.0

Happy Coding :-)

Meer Sadeq Billah
A: 

Hi Please check these link s for thumbnails of Images and Video....

For Audio: http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html http://mihaifonoage.blogspot.com/2009/11/displaying-images-from-sd-card-in.htmlFor Video:http://sadeqbillah.wordpress.com/2010/09/20/showing-video-thumbnails-in-android-2-0/

jetti