Intent cropIntent = new Intent("com.android.camera.action.CROP", null);
包:“com.android.camera.action”并不适用于所有Android设备(如Nexus 7)。是否有任何代码可以获取该设备使用的“裁剪包”的名称。
答案 0 :(得分:0)
您是否考虑过使用像这样的库:
https://github.com/biokys/cropimage
我发现com.android.camera.action.CROP有时可能会因手机而异,但并不总是可用,因此如果您想要发布它,可能会给您带来一些问题。
<强>更新强>
我已经使用Android 4.3测试了上面的库,它没有问题。您只需将库添加到项目中即可。
然后你可以用非常类似的方式编写你的方法:
private void performCrop(Uri picUri) {
//you have to convert picUri to string and remove the "file://" to work as a path for this library
String path = picUri.toString().replaceAll("file://", "");
try {
int aspectX = 750;
int aspectY = 1011;
Intent intent = new Intent(this, CropImage.class);
//send the path to CropImage intent to get the photo you have just taken or selected from gallery
intent.putExtra(CropImage.IMAGE_PATH, path);
intent.putExtra(CropImage.SCALE, true);
intent.putExtra("aspectX", aspectX);
intent.putExtra("aspectY", aspectY);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCurrentPhotoPath)));
startActivityForResult(intent, CROP);
}
catch (ActivityNotFoundException anfe) {
String errorMessage = "Your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}