Uri selectedImage = outputFileUri; InputStream imageStream =getContentResolver().openInputStream(selectedImage); try { BitmapFactory.Options bounds = new BitmapFactory.Options(); bounds.inJustDecodeBounds=true; BitmapFactory.decodeFile(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this), bounds); BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap bm = BitmapFactory.decodeFile(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this), opts); ExifInterface exif = new ExifInterface(Common.getRealPathFromURI(selectedImage, AddStoreActivity.this)); String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; int rotationAngle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; Matrix matrix = new Matrix(); matrix.setRotate(rotationAngle, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true); bitmap2 = rotatedBitmap;//BitmapFactory.decodeStream(imageStream); } catch(Exception ef) { bitmap2 = BitmapFactory.decodeStream(imageStream); }
Very simple, when in my android app i open camera..and take picture in portrait mode. i get the picture back rotated. how can i solve such issue?the above work i have done had no influence.
Try replacing this code
with this