如何在 Android 应用程序中不失真地显示照片
How to display Photograph without distortion in Android Application
我当前的 Android 应用程序允许用户 select 他们设备上的任何照片。
我使用此代码显示所有照片以允许用户 selection
final Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
照片被 select 编辑后,我会在我的主应用程序中显示它 activity。
我的主要 activity 使用如下的 LinearLayout:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<ImageView
android:id="@+id/photograph"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/select_photo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="Photo Select" />
</LinearLayout>
我使用此代码在我的应用程序中显示照片
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri imageUri = data.getData();
try {
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
imageView.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
select编辑的照片从未正确显示,例如它们或多或少地扭曲了。
我如何保证 selected 的任何照片都以正确的 dimensions/proportions 显示?
将 ImageView
的大小调整为 "the correct dimensions/proportions",或者使用 android:scaleType
来指明当图像应用于 ImageView
时您希望如何缩放图像。
我当前的 Android 应用程序允许用户 select 他们设备上的任何照片。
我使用此代码显示所有照片以允许用户 selection
final Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
照片被 select 编辑后,我会在我的主应用程序中显示它 activity。
我的主要 activity 使用如下的 LinearLayout:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<ImageView
android:id="@+id/photograph"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:src="@drawable/ic_launcher" />
<Button
android:id="@+id/select_photo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:text="Photo Select" />
</LinearLayout>
我使用此代码在我的应用程序中显示照片
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri imageUri = data.getData();
try {
final Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
imageView.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
select编辑的照片从未正确显示,例如它们或多或少地扭曲了。
我如何保证 selected 的任何照片都以正确的 dimensions/proportions 显示?
将 ImageView
的大小调整为 "the correct dimensions/proportions",或者使用 android:scaleType
来指明当图像应用于 ImageView
时您希望如何缩放图像。