Android 无法从相机中裁剪图像
首先,我很抱歉我的英语不好。 我试着从照相机的照片中截取图像 这是我的openCamera方法:Android 无法从相机中裁剪图像,android,camera,crop,Android,Camera,Crop,首先,我很抱歉我的英语不好。 我试着从照相机的照片中截取图像 这是我的openCamera方法: private void openCamera() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toStr
private void openCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());
// ******** code for crop image
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 150);
try {
intent.putExtra("return-data", true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
// Do nothing for now
}
}
下面是结果活动:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == PICK_FROM_CAMERA) {
Bundle extras = data.getExtras();
if (extras != null) {
photo = extras.getParcelable("data");
}
}
}
但它与
03-28 14:40:41.791 15198-15198/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3050)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.camera.action.CROP dat=file:///data/data/com.android.camera/files/crop-temp (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1518)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1390)
at
绝对不知道 使用以下代码
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
和OnActivityResult()
方法
Bundle extras=data.getExtras();
//获取裁剪后的位图
位图thePic=extras.getParcelable(“数据”)代码>。有很多。请用一个。对不起,你不对。这一意图是有效的。我通过-问题是什么来解决的?我不确定,但是你的回答很接近于一个正确的阿披舍克。看起来我们必须通过intent MediaStore.ACTION\u IMAGE\u CAPTURE获取照片,并且只有在使用intent com.android.camera.ACTION.CROP和照片的url后才能获取照片。再次感谢您的回答)请参考此,我尝试了此,但它不适合我。我已经解决了:)非常简单和好)