I have made an app in which user selects an image from gallery and that image is shown in the imageview.I have used resizing method to avoid Out of Memory issue.The problem is that when i select image which is having lower width and height the image is being properly set in the imageview,but when image width and height is large the image is rotated and set in the imageview.Why this is happening.Please help
CaptureImage
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult (requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
selectedImage = data.getData ();
try {
resizedGallery = decodeUri (getApplicationContext (), selectedImage);
} catch (FileNotFoundException e) {
e.printStackTrace ();
}
dialog = new Dialog (CaptureImage.this, android.R.style.Theme_DeviceDefault);
dialog.requestWindowFeature (Window.FEATURE_NO_TITLE);
dialog.setContentView (R.layout.confirmation_image);
dialog.getWindow ().setLayout (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ImageView image = (ImageView) dialog.findViewById (R.id.iv_selected_image);
image.setImageBitmap (resizedGallery);
image.setRotation (90);
ok_gallery = (Button) dialog.findViewById (R.id.bt_ok_gallery);
cancel = (Button) dialog.findViewById (R.id.bt_cancel);
ok_gallery.setOnClickListener (this);
cancel.setOnClickListener (this);
dialog.show ();
decodeUri Method
public static Bitmap decodeUri(Context c, Uri uri)
throws FileNotFoundException {
BitmapFactory.Options o = new BitmapFactory.Options ();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream (c.getContentResolver ().openInputStream (uri), null, o);
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp / 2 < 400 || height_tmp / 2 < 200)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options ();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream (c.getContentResolver ().openInputStream (uri), null, o2);
}