目前我正在使用默认的Android相机意图来裁剪图像。但是这在某些设备中无法正常工作。在纯Android设备中,不会调用裁剪或返回数据为空。有没有其他方法可以达到同样的目的。
目前我使用以下代码开始裁剪,
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setType("image/*");
if(picUri != null) {
cropIntent.setDataAndType(picUri, "image/*");
}
String tmpName = imageDir.getAbsolutePath() + File.separator + "img.jpg";
File tmpFile = new File(tmpName);
if (tmpFile.exists()) {
tmpFile.delete();
}
Uri tmpUri = Uri.fromFile(tmpFile);
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 16);
cropIntent.putExtra("aspectY", 9);
cropIntent.putExtra("outputX", 320);
cropIntent.putExtra("outputY", 180);
cropIntent.putExtra("return-data", true);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, tmpUri);
startActivityForResult(cropIntent, PIC_CROP);
答案 0 :(得分:3)
答案 1 :(得分:-1)
如果图像可以加载到内存中,您可以使用BitmapFactory.decodeFile加载到位图,然后使用createBitmap对位图进行裁剪。小心使用任意图像执行此操作,因为如果内存不足以加载图像,则解码将崩溃。