我遇到了低质量的裁剪图像问题。
这是我使用简单代码的情况。
下面的crop_image()方法。
Intent crop = new Intent("com.android.camera.action.CROP");
crop.setDataAndType(outputFileUri, "image/*");
crop.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
crop.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
crop.putExtra("crop", "true");
crop.putExtra("aspectX", 139);
crop.putExtra("aspectY", 185);
crop.putExtra("scale", true);
crop.putExtra("return-data", true);
startActivityForResult(crop, CROP_AFTER_CAMERA);
从相机裁剪图像后,设置ImageView
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_FROM_CAMERA && resultCode == RESULT_OK) {
if (outputFileUri != null) {
crop_image();
}
}
else if (requestCode == EDIT_CROPPED_IMAGE) {
}
else if (requestCode == CROP_AFTER_CAMERA) {
if (data != null) {
Bundle bundle = data.getExtras();
Bitmap cropBit = bundle.getParcelable("data");
imgView.setImageBitmap(cropBit);
saveBitmap(cropBit);
}
}
else if (resultCode == RESULT_CANCELED) {
Provider.deleteFile(getBaseContext(), outputFileUri);
}
}
之后,我使用compress方法存储位图图像。
OutputStream out = null;
File image_file = new File(targetFolder + filename);
try {
image_file.createNewFile();
out = new FileOutputStream(image_file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
out.close();
}
}
位图图像(存储的位图图像和ImageView)的结果都有
质量低。
如何恢复图像的质量?
谢谢你的帮助!!