目前我正在尝试在捕捉图像并将图像旋转到正确方向(相机问题)后,在图像视图上显示旋转约5度的图像。现在的问题是在将图像设置为旋转5度的图像视图imageview.setRotation(5)
后,图像视图本身变为别名。我很确定imageview是一个混叠的,因为我的图像有一个5dp的填充,两侧有一个白色边框但是如果我错了请纠正我。
我到目前为止尝试的解决方案是this,但示例解决方案适用于自定义视图中已设置的图像,我不习惯配置或进一步自定义自定义视图以根据我的工作需要。虽然他的问题几乎和我的一样。
我也尝试过this one动态应用抗锯齿功能但效果不佳。
到目前为止,这是我的代码:
imageview = (ImageView) findViewById(R.id.img_preview);
imageview.setRotation(5);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String img_path = extras.getString("img_path");
File image_file = new File(img_path);
try {
Bitmap captured_image = applyOrientation(BitmapFactory.decodeFile(img_path),resolveBitmapOrientation(image_file));
imageview.setImageBitmap(captured_image);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我旋转图像的代码,也许有人可以帮助修复它,所以这里是:
private int resolveBitmapOrientation(File bitmapFile) throws IOException {
ExifInterface exif = null;
exif = new ExifInterface(bitmapFile.getAbsolutePath());
return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
}
private Bitmap applyOrientation(Bitmap bitmap, int orientation) {
int rotate = 0;
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
default:
return bitmap;
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(rotate);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}