0

I was using the following code to set the captured image to imageview. When the image captured in landscape view it shows in landscape view but when the image captured in portrait view it also shown in landscape view.

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1 && resultCode == Activity.RESULT_OK){
        try {
            Bitmap thumbnail = MediaStore.Images.Media.getBitmap(
                    getContext().getContentResolver(), imageUri);
            img_document.setImageBitmap(thumbnail);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

1 Answers1

0

I have also faced the same issue.But resizing image helped me.You can use following code for resizing image:

Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);

public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
    boolean filter) {
float ratio = Math.min(
        (float) maxImageSize / realImage.getWidth(),
        (float) maxImageSize / realImage.getHeight());
int width = Math.round((float) ratio * realImage.getWidth());
int height = Math.round((float) ratio * realImage.getHeight());

Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
        height, filter);
return newBitmap;
}

Hope it helps!!!

Gowthaman M
  • 7,600
  • 7
  • 31
  • 52
Anu Bhalla
  • 432
  • 4
  • 11