1

I have an ImageView (square), I need to display there picture in the certain way, in case if the picture has been taken in the vertical orientation there should be space on the left and right side of the square (picture 1), in case if the picture has been taken in the landscape orientation, there should be space in the top and bottom of the square. How is possible to do that? Maybe exist some special ScaleType for that?

Picture 1:

enter image description here

Picture 2:

enter image description here

Lucky_girl
  • 4,543
  • 6
  • 42
  • 82
  • 2
    ImageView.ScaleType.CENTER_INSIDE: https://developer.android.com/reference/android/widget/ImageView.ScaleType.html – yongsunCN Jul 06 '16 at 18:55
  • @youngsunCN, it works perfectly well with the landscape picture, but pictures which were taken in the vertical orientation displays the same way as landscape (but with the wrong rotation). Why is that? – Lucky_girl Jul 06 '16 at 19:27
  • could you please upload a example image – yongsunCN Jul 06 '16 at 19:34
  • @yongsunCN yeah, I mean, that picture displays as it has been rotated by 90 degrees. – Lucky_girl Jul 06 '16 at 19:36
  • if your image was rotated by 90 degrees, it seems not a scale type issue. you will need provide more info, such as code, for people to further help you. – yongsunCN Jul 06 '16 at 19:39
  • @yongsunCN okay, thank you a lot! will try to found where is the problem, if wouldn't found, will create a new question, at least it works good with the landscape pictures right now! – Lucky_girl Jul 06 '16 at 19:44

1 Answers1

1

I hope this example can help you:

//OnActivityResult method

                    Uri selectedImage = data.getData();
                    if (selectedImage == null) {
                        imagePath = data.getStringExtra(GOTOConstants.IntentExtras.IMAGE_PATH);

                        Bitmap my_bitmap_camera = BitmapFactory.decodeFile(imagePath);

                        ExifInterface exif = new ExifInterface(imagePath);
                        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

                        switch (orientation){
                            case ExifInterface.ORIENTATION_ROTATE_90:
                                Matrix matrix = new Matrix();
                                matrix.postRotate(90);
                                my_bitmap_camera = Bitmap.createBitmap(my_bitmap_camera, 0, 0, my_bitmap_camera.getWidth(), my_bitmap_camera.getHeight(), matrix, true);
                                break;
                        }

                        ivScreenshot1.setImageBitmap(my_bitmap_camera);
                    }

//XML

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/ivScreenshot1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            </RelativeLayout>

//Also you can check this post: How to get the Correct orientation of the image selected from the Default Image gallery

Community
  • 1
  • 1
L.Velazquez
  • 1,696
  • 1
  • 11
  • 7