在我的应用中,我在活动B 中构建了一个相机功能。然后,所选图片将放置在imageView
B 中。
活动B --->一个imageView B,用于放置所选图像
所选图像可以显示在ImageView
B 上,但看起来很模糊。请告诉我该怎么办。提前致谢 !
活动B
private void activeGallery() {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case RESULT_LOAD_IMAGE:
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK & null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null,null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap a = (BitmapFactory.decodeFile(picturePath));
photo=scaleBitmap(a,200,200);
imageView.setImageBitmap(photo);
}
}
}
public static Bitmap scaleBitmap(Bitmap bitmap, int wantedWidth, int wantedHeight) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float scaleWidth = ((float) wantedWidth) / width;
float scaleHeight = ((float) wantedHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, wantedWidth, wantedHeight, false);
return resizedBitmap;
}
原始图片
放置在ImageView B中(看起来模糊)
答案 0 :(得分:0)
如何修复imageView的大小?
你可以试试这个
<ImageView
android:id="@+id/YourImageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:scaleType="centerInside"
android:gravity="right|center_vertical"
android:padding="10px"
/>
来自here
的来源