Reputation: 4883
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:
Picture 2:
Upvotes: 1
Views: 49
Reputation: 1736
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
Upvotes: 1