Get Bitmap from an Uri

targetUri = Intentdata.getData();
try { bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri)); targetImage.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } 
Uri getData()

Retrieve data this intent is operating on.
final static Bitmap getBitmap(ContentResolver cr, Uri url)

Retrieves an image for the given url as a Bitmap.

Bundle extras = Intentdata.getExtras();

Bitmap bmp = (Bitmap) extras.get(“data”); //

Object get(String key)

Returns the entry with the given key as an object.

Google – Loading Large Bitmaps Efficiently

Photo Location:

1.  the uri returned from build-in Gallery app is in the format of “content://media/external/images/…”.

Uri targetUri = data.getData();
static Uri getContentUri(String volumeName)

Get the content:// style URI for the image media table on the given volume.
2. convert it to the real path format (eg. /mnt/sdcard/dropbox/Eric/....png), the following function can be used.
public String getRealPathFromURI(Uri contentUri) {
       String[] proj = { MediaStore.Images.Media.DATA };
       Cursor cursor = managedQuery(contentUri, proj, null, null, null);
       int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       return cursor.getString(column_index);
final Cursor managedQuery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

This method is deprecated. Use CursorLoader instead.

 Bitmap orientation:

Exif orientation

For convenience, here is what the letter F would look like if it were tagged correctly and displayed by a program that ignores the orientation tag (thus showing the stored image):
1        2       3      4         5            6           7          8

888888  888888      88  88      8888888888  88                  88  8888888888
88          88      88  88      88  88      88  88          88  88      88  88
8888      8888    8888  8888    88          8888888888  8888888888          88
88          88      88  88
88          88  888888  888888

ExifInterface exif = new ExifInterface(filename);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);//grab the orientation of the image,the most important values are 3, 6 and 8. If the orientation is 6, for example, you can rotate the image like this:

Matrix matrix = new Matrix();
rotatedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: