Gallery images get rotated when saved - android

I have been trying to save images to Firebase Storage but I noticed that almost all pictures saved from Gallery/Google Drive get rotated.(usually by 90 degrees)
Reading through older posts I realized that this is a common issue and I tried solving it by trying either solution from this post , or from this one , this one and I could go on.
After roughly 8 hours I finally decided to ask here. Is there a better and easier implementation to stop the images from getting rotated?
My last (and unsuccessful, obviously) implementation using ExifInterface (which returns all the time 0) is this one:
Selecting picture
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_PICK);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
OnActivityResult
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContext().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
int rotateImageAngle = getPhotoOrientation(getContext(), selectedImage, filePath);
try {
bitmap = MediaStore.Images.Media.getBitmap(getContext().getContentResolver(), selectedImage);
// Log.d(TAG, String.valueOf(bitmap));
addPictureButton.setText("Done");
} catch (IOException e) {
e.printStackTrace();
}
if( bitmap != null)
{
RotateBitmap(bitmap , rotateImageAngle);
}
}
Helper methods
public int getPhotoOrientation(Context context, Uri imageUri, String imagePath){
int rotate = 0;
try {
context.getContentResolver().notifyChange(imageUri, null);
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
Log.i("RotateImage", "Exif orientation: " + orientation);
Log.i("RotateImage", "Rotate value: " + rotate);
} catch (Exception e) {
e.printStackTrace();
}
return rotate;
}
public static Bitmap RotateBitmap(Bitmap source, int angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
Note: If needed I will add the code that uploads images to Firebase

I have come to a solution thanks to this post.
I am going to post below a modified working version of the code for anybody that has this issue.
Fire up picture selection from gallery
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, PICK_IMAGE_REQUEST);
OnActivityResult checking original roatation of the selected picture
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK && requestCode == PICK_IMAGE_REQUEST) {
// Get selected gallery image
Uri selectedPicture = data.getData();
// Get and resize profile image
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// TRY getactvity() as well if not work
Cursor cursor = getContext().getContentResolver().query(selectedPicture, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
loadedBitmap = BitmapFactory.decodeFile(picturePath);
ExifInterface exif = null;
try {
File pictureFile = new File(picturePath);
exif = new ExifInterface(pictureFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
int orientation = ExifInterface.ORIENTATION_NORMAL;
if (exif != null)
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
loadedBitmap = rotateBitmap(loadedBitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
loadedBitmap = rotateBitmap(loadedBitmap, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
loadedBitmap = rotateBitmap(loadedBitmap, 270);
break;
}
imageView.setImageBitmap(loadedBitmap);
}
}
RotateBitmap method
public static Bitmap rotateBitmap(Bitmap bitmap, int degrees) {
Matrix matrix = new Matrix();
matrix.postRotate(degrees);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}

Related

Orientation of image from gallery is always 0

I'm trying to load an image from gallery in a ImageView. This code work correctly on Huawei p10, but don't work correctly on Samsung s5 and other devices. When i load the image the orientation is not correctly.
I'm using this function to load from gallery but the orientation is always 0.
public void loadPostImage(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE1) {
selectedImageUri = data.getData();
if (null != selectedImageUri) {
flag=true;
path = selectedImageUri.getPath();
int orientation = getOrientation(getApplicationContext(), selectedImageUri);
Log.e("image path", path + "");
image_post.setImageURI(selectedImageUri);
}
}
}
}
private static int getOrientation(Context context, Uri photoUri) {
Cursor cursor = context.getContentResolver().query(photoUri,
new String[]{MediaStore.Images.ImageColumns.ORIENTATION}, null, null, null);
if (cursor.getCount() != 1) {
cursor.close();
return -1;
}
cursor.moveToFirst();
int orientation = cursor.getInt(0);
cursor.close();
cursor = null;
return orientation;
}
I tried also with EXIF. But nothing is changed.
public void controlRotate(Uri photoUri) throws IOException {
ExifInterface exif = new ExifInterface(photoUri.getPath());
int exifRotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
switch (exifRotation) {
case ExifInterface.ORIENTATION_ROTATE_90: {
float photoRotation = 90.0f;
break;
}
case ExifInterface.ORIENTATION_ROTATE_180: {
float photoRotation = 180.0f;
break;
}
case ExifInterface.ORIENTATION_ROTATE_270: {
float photoRotation = 270.0f;
break;
}
}
}
I resolved the problem using this snippet
public void orientation(Uri selectedImageUri){
Uri uri = selectedImageUri; // the URI you've received from the other app
InputStream in = null;
try {
in = getContentResolver().openInputStream(uri);
ExifInterface exifInterface = new ExifInterface(in);
int rotation = 0;
int orientation = exifInterface.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotation = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotation = 270;
break;
}
// Now you can extract any Exif tag you want
// Assuming the image is a JPEG or supported raw format
} catch (IOException e) {
// Handle any errors
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {}
}
}
}

Image rotated when chosen from gallery

I am using the following code to get the orientation of the selected image so that if it was taken vertically, when selected from gallery it would not be shown horizontally.
The error is occuring in the
File imageFile = new File(selectedImage.toString()); in the parameter selectedImage.toString()) since when I changed the initial int rotate=90 and chose a vertical image the result was good.
Am I passing the parameter to the File correct?
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
BitmapFactory.Options options;
if (resultCode == RESULT_OK && requestCode == PICTURE_SELECTED) {
try {
options = new BitmapFactory.Options();
options.inSampleSize = 4;
Uri selectedImage = data.getData();
InputStream stream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(stream, null, options);
stream.close();
//orientation
try {
int rotate = 0;
try {
File imageFile = new File(selectedImage.toString());
ExifInterface exif = new ExifInterface(
imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
yourSelectedImage = Bitmap.createBitmap(yourSelectedImage , 0, 0, yourSelectedImage.getWidth(), yourSelectedImage.getHeight(), matrix, true); }
catch (Exception e) {}
//end of orientation
imgButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
imgButton.setImageBitmap(yourSelectedImage);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Could not open file.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Image was not selected", Toast.LENGTH_LONG).show();
}
super.onActivityResult(requestCode, resultCode, data);
}
Modify your method like this:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
BitmapFactory.Options options;
if (resultCode == RESULT_OK && requestCode == PICTURE_SELECTED) {
try {
options = new BitmapFactory.Options();
options.inSampleSize = 4;
Uri selectedImage = data.getData();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePath, null, null, null);
cursor.moveToFirst();
String mImagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
InputStream stream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(stream, null, options);
stream.close();
//orientation
try {
int rotate = 0;
try {
ExifInterface exif = new ExifInterface(
mImagePath);
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
yourSelectedImage = Bitmap.createBitmap(yourSelectedImage , 0, 0, yourSelectedImage.getWidth(), yourSelectedImage.getHeight(), matrix, true); }
catch (Exception e) {}
//end of orientation
imgButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
imgButton.setImageBitmap(yourSelectedImage);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Could not open file.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Image was not selected", Toast.LENGTH_LONG).show();
}
}
for image handling compile picasso is best library using it you can easily handle images using it you can load image from cache also and increase performance of your app so try to avoid doing lots of code and add following line in your build gradle and then use picasso in your code.
compile 'com.squareup.picasso:picasso:2.5.0'

Get image name from selected image in gallery

At the moment I am selecting an image from gallery and the whole path is shown example (/storage/emulated.0/DCIM/Camera/123.jpg) in the textview whereas I only want the name of the image to be shown example 123.jpg.
public String getRealPathFromURI(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
#SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
BitmapFactory.Options options;
if (resultCode == RESULT_OK && requestCode == PICTURE_SELECTED) {
try {
options = new BitmapFactory.Options();
options.inSampleSize = 4;
Uri selectedImage = data.getData();
String s= getRealPathFromURI(selectedImage);
imageName.append(s);
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
String[] filePath = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePath, null, null, null);
cursor.moveToFirst();
String mImagePath = cursor.getString(cursor.getColumnIndex(filePath[0]));
InputStream stream = getContentResolver().openInputStream(selectedImage);
Bitmap yourSelectedImage = BitmapFactory.decodeStream(stream, null, options);
stream.close();
//---orientation---
try {
int rotate = 0;
try {
ExifInterface exif = new ExifInterface(
mImagePath);
dateTaken.append(exif.getAttribute(ExifInterface.TAG_DATETIME));
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
Matrix matrix = new Matrix();
matrix.postRotate(rotate);
yourSelectedImage = Bitmap.createBitmap(yourSelectedImage , 0, 0, yourSelectedImage.getWidth(), yourSelectedImage.getHeight(), matrix, true);
}
catch (Exception e) {}
//---end of orientation---
imgButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
imgButton.setImageBitmap(yourSelectedImage);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Could not open file.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Image was not selected", Toast.LENGTH_LONG).show();
}
Log.i(TAG, "onActivityResult - Portal");
}
Followed this link Get filepath and filename of selected gallery image in Android
You need to perform a String operation.follwoing code will help you out.
String path=":/storage/sdcard0/DCIM/Camera/1414240995236.jpg";
String filename=path.substring(path.lastIndexOf("/")+1);
possible duplicate of :
How to get file name from file path in android

How to set the imgeview Orientation to be portrait

I 'm working on an application to capture image from camera and get image from gallery the images will be shown on Image view every thing is work fine but my problem is in the image that in landscape orientation not appear in the right way can any one help me to convert the image in portrait orientation
this is my code
open.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, REQUEST_CODE);
}
});
camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK)
try {
if (bitmap != null) {
bitmap.recycle();
}
InputStream stream = getContentResolver().openInputStream(
data.getData());
bitmap = BitmapFactory.decodeStream(stream);
stream.close();
pic.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
if (bitmap != null) {
bitmap.recycle();
}
bitmap = (Bitmap) data.getExtras().get("data");
pic.setImageBitmap(bitmap);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
Here are two helper methods that I use to rotate bitmaps to the correct orientation. You simply pass the method the bitmap you would like to rotate along with the absolute path to it's saved file location, which can be obtained with the getRealPathFromURI helper also supplied, and you will receive a correctly rotated bitmap.
Your code
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
if (bitmap != null) {
bitmap.recycle();
}
bitmap = (Bitmap) data.getExtras().get("data");
String absPath = getRealPathFromURI(data.getData());
Bitmap rotatedBitmap = rotateBitmap(absPath, bitmap);
pic.setImageBitmap(rotatedBitmap);
}
Helpers
/**
* Converts a Uri to an absolute file path
*
* #param contentUri Uri to be converted
* #return String absolute path of Uri
*/
public String getRealPathFromURI(Uri contentUri) {
// Can post image
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = this.getContentResolver().query(contentUri,
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.moveToFirst();
return cursor.getString(column_index);
}
/**
* Rotates the bitmap to the correct orientation for displaying
*
* #param filepath absolute path of original file
* #param originalBitmap original bitmap to be rotated
* #return
*/
private Bitmap rotateBitmap(String filepath, Bitmap originalBitmap) {
try {
// Find the orientation of the original file
ExifInterface exif = new ExifInterface(filepath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
Matrix matrix = new Matrix();
// Find correct rotation in degrees depending on the orientation of the original file
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.postRotate(180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.postRotate(270);
break;
default:
return originalBitmap;
}
// Create new rotated bitmap
Bitmap rotatedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth(),
originalBitmap.getHeight(), matrix, true);
return rotatedBitmap;
} catch (IOException e) {
Log.d(TAG, "File cannot be found for rotating.");
return originalBitmap;
}
}

Android Camera Orientation ISsue

pictures taken in vertical format are saved in landscape format and vice-versa. I am using Android camera by using this intent
Intent captureImage = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureImage.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(captureImage, CAMERA_PIC_REQUEST);
onActivityResult() I am just saving image URL to my database and displaying it in a listview.
but there orientatiuon changes. The same will happen if I choose image from gallery and save it.
I want the orientation in which photo has been taken. I dont want to change it. Is anybody have a solutin on this.
Some devices doesn't rotate image after it was taken but just write its orientation information into Exif data. So before using taken photo you should call method like :
private int resolveBitmapOrientation(File bitmapFile) throws IOException {
ExifInterface exif = null;
exif = new ExifInterface(bitmapFile.getAbsolutePath());
return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
}
to check its orientation. Then apply:
private Bitmap applyOrientation(Bitmap bitmap, int orientation) {
int rotate = 0;
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
default:
return bitmap;
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(rotate);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}
and use this new bitmap in your listview. Or it's even better to call this methods just after your photo was taken and override it with new rotated one.
In case if you are receiving Bitmap data as Uri the following method can be used to retrieve its filepath:
public static String getPathFromURI(Context context, Uri contentUri) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
DocumentsContract.isDocumentUri(context, contentUri)) {
return getPathForV19AndUp(context, contentUri);
} else {
return getPathForPreV19(context, contentUri);
}
}
private static String getPathForPreV19(Context context, Uri contentUri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
try {
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
return cursor.getString(columnIndex);
} finally {
cursor.close();
}
}
return null;
}
#TargetApi(Build.VERSION_CODES.KITKAT)
private static String getPathForV19AndUp(Context context, Uri contentUri) {
String documentId = DocumentsContract.getDocumentId(contentUri);
String id = documentId.split(":")[1];
String[] column = { MediaStore.Images.Media.DATA };
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = context.getContentResolver().
query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{ id }, null);
if (cursor != null) {
try {
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
return cursor.getString(columnIndex);
}
} finally {
cursor.close();
}
}
return null;
}
You can also follow by this way:
static Uri image_uri;
static Bitmap taken_image=null;
image_uri=fileUri; // file where image has been saved
taken_image=BitmapFactory.decodeFile(image_uri.getPath());
try
{
ExifInterface exif = new ExifInterface(image_uri.getPath());
//Since API Level 5
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
RotateBitmap(taken_image, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
RotateBitmap(taken_image, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
RotateBitmap(taken_image, 270);
break;
case ExifInterface.ORIENTATION_NORMAL:
taken_image=decodeScaledBitmapFromSdCard(image_uri.getPath(), 200, 200);
RotateBitmap(taken_image, 0);
break;
}
}
catch (OutOfMemoryError e)
{
Toast.makeText(getActivity(),e+"\"memory exception occured\"",Toast.LENGTH_LONG).show();
}
public Bitmap RotateBitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
round_Image = source;
round_Image = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}

Categories

Resources