【发布时间】:2013-10-24 01:27:37
【问题描述】:
我发现了很多关于如何裁剪图像的问题。但是,有没有办法通过一个意图来启动编辑图像活动。我尝试使用com.android.camera.action.EDIT,但它不起作用。我想要做的是当我点击一个按钮时,启动编辑图像的活动,如下图所示:
这就像我从图库中打开一张图片并从菜单中单击Edit。
【问题讨论】:
我发现了很多关于如何裁剪图像的问题。但是,有没有办法通过一个意图来启动编辑图像活动。我尝试使用com.android.camera.action.EDIT,但它不起作用。我想要做的是当我点击一个按钮时,启动编辑图像的活动,如下图所示:
这就像我从图库中打开一张图片并从菜单中单击Edit。
【问题讨论】:
Intent editIntent = new Intent(Intent.ACTION_EDIT);
editIntent.setDataAndType(uri, "image/*");
editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(editIntent, null));
【讨论】:
startActivityForResult(),那么图像编辑器可能会出现三种结果。用户编辑图像并且 resultCode 是 Activity.RESULT_OK ,用户不进行任何编辑并单击 Done 或 Save,这取决于返回结果代码 Activity.RESULT_CANCELED 的编辑器,或者用户按下返回Activity.RESULT_CANCELED 的resultCode 的后退按钮。为什么最后两个选项返回相同的 resultCode 值?您如何区分这两者?
Activity.RESULT_OK 的操作。是怎么做到的?调用意图时我应该设置其他参数吗?
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(yourimageuri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 640);
intent.putExtra("outputY", 640);
intent.putExtra("scale", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outPath);
intent.putExtra("return-data", false);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true);
startActivityForResult(intent, CAMERA_CROP_RESULT);
【讨论】:
EDITOR_CROP 是我正在寻找的东西。有没有办法启动它,但不能启动裁剪。只需启动编辑器,让用户选择他想做的事情。我尝试删除 intent.putExtra("crop", "true"); 但它不起作用。还有一个问题:这是否适用于 android 3.2,因为我的应用应该支持 3.2+
找到了一个可以用于此的库,并且运行良好。该库可以在here找到。
【讨论】: