Java 如何以特定方式在ImageView中显示图片
我有一个ImageView(正方形),我需要以特定的方式显示图片,如果图片是在垂直方向拍摄的,那么正方形的左右两侧应该有空间(图片1),如果图片是在横向方向拍摄的,广场的顶部和底部应该有空间。这怎么可能呢?可能存在一些特殊的ScaleType 图1: 图2:Java 如何以特定方式在ImageView中显示图片,java,android,android-imageview,Java,Android,Android Imageview,我有一个ImageView(正方形),我需要以特定的方式显示图片,如果图片是在垂直方向拍摄的,那么正方形的左右两侧应该有空间(图片1),如果图片是在横向方向拍摄的,广场的顶部和底部应该有空间。这怎么可能呢?可能存在一些特殊的ScaleType 图1: 图2: 我希望这个例子能帮助您: //OnActivityResult方法 Uri selectedImage = data.getData(); if (selec
我希望这个例子能帮助您: //OnActivityResult方法
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
//你也可以查看这篇文章:ImageView.ScaleType.CENTER\u内部:@youngsunCN,它与横向照片配合得非常好,但垂直方向拍摄的照片显示方式与横向相同(但旋转错误)。为什么?你能上传一个例子吗image@yongsunCN是的,我的意思是,图片显示为旋转了90度。如果你的图像旋转了90度,这似乎不是缩放类型的问题。您需要提供更多信息,如代码,以便人们进一步帮助您。
<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>