我正在使用以下代码将捕获的图像设置为imageview。当以横向视图捕获图像时,它以横向视图显示,但是当以纵向视图捕获图像时,它也以横向视图显示。
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == Activity.RESULT_OK){
try {
Bitmap thumbnail = MediaStore.Images.Media.getBitmap(
getContext().getContentResolver(), imageUri);
img_document.setImageBitmap(thumbnail);
} catch (Exception e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
我也遇到过同样的问题。但是调整图像大小对我有帮助。您可以使用以下代码调整图像大小:
Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);
public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
boolean filter) {
float ratio = Math.min(
(float) maxImageSize / realImage.getWidth(),
(float) maxImageSize / realImage.getHeight());
int width = Math.round((float) ratio * realImage.getWidth());
int height = Math.round((float) ratio * realImage.getHeight());
Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
height, filter);
return newBitmap;
}
希望有帮助!