【发布时间】:2009-12-29 07:21:24
【问题描述】:
我正在尝试拍摄后裁剪图像,我的代码如下:
private void doTakePhotoAction() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 96);
intent.putExtra("outputY", 96);
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
//Do nothing for now
}
}
使用上面的代码,我可以进入裁剪模式,裁剪图片。但是,不强制使用 1:1 纵横比,也不是 outputX 和 outputY。我相信这是因为目的是拍照,而不是裁剪。我还编写了另一种方法从 Intent 中获取 getData(),然后使用以下方法:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.camera", "com.android.camera.CropImage");
但是,当我这样做时,我收到以下运行时错误:
E/AndroidRuntime(14648): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.camera/com.android.camera.CropImage}: java.lang.NullPointerException
感谢您的帮助! :)
【问题讨论】:
标签: android