Image Uri to Thumbnail Uri

All your problems with Audio, Video and Images.

Image Uri to Thumbnail Uri

Postby danh32 » Tue Mar 23, 2010 4:34 am

Hello everyone,

I'm using a gallery to display selected images from the SD card to the user (as an email attachment manager).

I have the regular image uri as returned from android's build in gallery launched from this code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Intent intent = new Intent();
  3.  
  4. intent.setType("image/*");
  5.  
  6. intent.setAction(Intent.ACTION_GET_CONTENT);
  7.  
  8. startActivityForResult(intent, PICTURE_RETURN);
  9.  
  10.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Using these full sized images in the gallery, however, quickly exceeds the VM's memory limit. So I've been trying to get a thumbnail version of the same image, but am failing terribly.

Here is my getView from the ImageAdapter class (pics is a Vector<Uri>):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public View getView(int position, View convertView, ViewGroup parent) {
  3.  
  4.                 ImageView i = new ImageView(mContext);
  5.  
  6.          if (convertView == null) {
  7.  
  8.                 Uri uri = pics.elementAt(position);
  9.  
  10.                 Log.i(TAG, "Image Uri = " + uri.toString());
  11.  
  12.                 try {
  13.  
  14.                         i.setImageURI(uri);
  15.  
  16.                         i.setScaleType(ImageView.ScaleType.FIT_XY);
  17.  
  18.                         i.setLayoutParams(new Gallery.LayoutParams(136, 136));
  19.  
  20.                         i.setBackgroundResource(mGalleryItemBackground);
  21.  
  22.                 } catch (Exception e) {
  23.  
  24.                 }
  25.  
  26.         }
  27.  
  28.         return i;
  29.  
  30.     }
  31.  
  32.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Is there some way to use the uri obtained to get the thumbnail image? Sorry if I've overlooked something obvious. Any help is much appreciated!

Thanks,
--Dan
danh32
Freshman
Freshman
 
Posts: 5
Joined: Mon Mar 22, 2010 6:58 am

Top

Postby senormoll » Tue Mar 23, 2010 5:05 pm

Use the MediaStore THUMBNAILS database to get the thumbnail of any given image on the phone. The URI of the file can get you many things using the mediastore, including the picture itself, thumbnail, author, date added/modified, etc.
senormoll
Developer
Developer
 
Posts: 29
Joined: Tue Feb 23, 2010 2:50 am

Postby danh32 » Tue Mar 23, 2010 6:00 pm

senormoll wrote:Use the MediaStore THUMBNAILS database to get the thumbnail of any given image on the phone. The URI of the file can get you many things using the mediastore, including the picture itself, thumbnail, author, date added/modified, etc.


Thank you very much for your response. I am trying to use the 'getThumbnail()' method, but it requires an id of the original image. Is there any way to get this id from the original image's uri?
danh32
Freshman
Freshman
 
Posts: 5
Joined: Mon Mar 22, 2010 6:58 am

Postby senormoll » Tue Mar 23, 2010 7:47 pm

Yea the database requires each item to have a unique id like any other database, so just use the MediaStore.Media.Images._ID

I think that's it I'm on my phone so I can't check or find a link for you. Google mediastore example and one of the first few results is a gallery. it'll show you how to use the database.
senormoll
Developer
Developer
 
Posts: 29
Joined: Tue Feb 23, 2010 2:50 am

Postby danh32 » Tue Mar 23, 2010 8:56 pm

So if I'm understanding correctly, I should be querying the 'full-sized image database' for the ID of the uri that I have. I should then use that ID to query the thumbnail database for the corresponding thumbnail uri?

I'm also on my phone, so I'll be tinkering with this later. Just want to make sure I'm not way off-base.
danh32
Freshman
Freshman
 
Posts: 5
Joined: Mon Mar 22, 2010 6:58 am

Postby danh32 » Wed Mar 24, 2010 3:41 am

Ok. I've gotten this to work:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Uri originalUri = intent.getData();
  3.  
  4. Uri thumb = Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, originalUri.getLastPathSegment());
  5.  
  6.  
  7.  
  8.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Thanks so much for your help!
danh32
Freshman
Freshman
 
Posts: 5
Joined: Mon Mar 22, 2010 6:58 am

Top

try

Postby padmakumar » Thu Mar 25, 2010 4:06 pm

intent.putExtra(Intent.EXTRA_STREAM, getLastImageThumbUri());

public Uri getLastImageThumbUri() {

String[] proj = {MediaStore.Images.Media.DATA};

Cursor cursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, // Which
// columns
// to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)

int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToLast();
return Uri.parse("file://" + cursor.getString(column_index));

}
User avatar
padmakumar
Freshman
Freshman
 
Posts: 2
Joined: Wed Mar 17, 2010 2:20 pm
Location: hydbad

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google Feedfetcher and 24 guests