在我的应用程序中,我必须从相机捕获图像或从库中导入,在活动中的imageview中显示它.一切都很好,我从两者都获得图像,并能够毫无例外地在imageview上设置它.但有时图像不能正确缩放并垂直拉伸或方向改变.请帮帮我.
这是我的代码解码从官方Android文档引用的图像:
public static Bitmap decodeSampledBitmapFromResource(File photoFile, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
BitmapFactory.decodeStream(new FileInputStream(photoFile), null,
options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeStream(new FileInputStream(photoFile),
null, options);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int …Run Code Online (Sandbox Code Playgroud)