Getting path to full size image from thumbnail

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Getting path to full size image from thumbnail

Postby DroidDoes22 » Sun Mar 04, 2012 6:29 pm

I'm displaying all photos on the users device in a gridview by querying the Mediastore and returning the thumbnail of each image. After displaying the images, my app needs to be able to perform 4 functions on each image. These are view, move, delete and share. But my problem is that I can't get the path to the FULL image on the device, so that I can create are URI instance and use that to perform those actions. Here's my implementation below, any advice on what I'm doing wrong and/or how to correctly use the imagePath member to get access to the ful image? Any workarounds?

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

int columnIndex = 0; String[] projection = {MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_C projection, null, null, null);

if(cursor != null){ columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.

cursor.moveToPosition(position); imagePath = cursor.getString(columnIndex);

FileInputStream is = null; BufferedInputStream bis = null;

try{ is = new FileInputStream(new File(imagePath)); bis = new BufferedInputStream(is); Bitmap bitmap = BitmapFactory.decodeStream(bis); useThisBitmap = Bitmap.createScaledBitmap(bitmap, parent.getWidth(), parent.getHeight(), true);

bitmap.recycle(); }catch(Exception e){ //Try to recover } finally{ try{ if(bis != null){ bis.close(); } if(is != null){ is.close(); } cursor.close(); projection = null; }catch(Exception e){

} } } Toast.makeText(this, " " + imagePath, Toast.LENGTH_SHORT).show();
DroidDoes22
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu May 26, 2011 4:48 am

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Google [Bot] and 5 guests