【问题标题】:Is com.android.camera.action.CROP not available for Android jelly bean 4.3?com.android.camera.action.CROP 是否不适用于 Android jelly bean 4.3?
【发布时间】:2013-08-02 09:29:56
【问题描述】:

我在使用相机拍照后使用 com.android.camera.action.CROP 进行裁剪。

以下是我在 4.3 之前使用的代码。

Intent cropIntent = new Intent("com.android.camera.action.CROP");
                        cropIntent.setType("image/*");
                        cropIntent.putExtra("crop", "true");
                        cropIntent.putExtra("aspectX", 1);
                        cropIntent.putExtra("aspectY", 1);
                        cropIntent.putExtra("outputX", Conf.getInt("IMAGE_WIDTH"));
                        cropIntent.putExtra("outputY", Conf.getInt("IMAGE_HEIGHT"));
                        cropIntent.putExtras(extras);
                        startActivityForResult(cropIntent, CROP_REQUEST_CODE);

但是现在由于 android 裁剪操作会将您带到图库(因为图库默认使用裁剪),因此此裁剪方法失败(照片未保存到图库)。

有没有人知道解决这个问题的方法。我可以在哪里使用从相机拍摄的照片上的裁剪

【问题讨论】:

标签: android camera


【解决方案1】:

复制之前提出的类似问题的答案..

您是否考虑过只使用这样的库:

GitHubLink

我发现 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();
}

【讨论】:

  • 如何在 Android Studio 中将项目添加为库?
  • 该库仅允许您为应用程序使用设置内存,因此您将无法裁剪大分辨率图像。您仍然可以在此处显示的 4.3 上使用标准 android Intent stackoverflow.com/a/19435016/1499064
  • @JohnBale 您必须在主目录下创建一个 libs 文件夹,然后将其添加到您的 build.gradle 文件中
  • 它建议您希望裁剪照片的路径..您可以提供当前照片路径,仅将其替换为裁剪后的路径..
  • 您是否真的看到了“我发现 com.android.camera.action.CROP 有时会因手机而异”的行为。我想知道您发现了什么偏差?
【解决方案2】:

根据@commonsware 's post
此意图基于AOSP camera app,它在目标设备中可能可用也可能不可用,对于某些 4.3 设备它可能有效,而对于某些设备则不能。

因此,更好的方法是使用找到的任何开源库 at Android arsenal
(确保它们也不是基于AOSP)。

【讨论】:

  • 有没有人能证明它在“某些设备”上不起作用?另外,我们在这里谈论的是哪些设备?三星、HTC?
【解决方案3】:

我已经尝试了几个裁剪器。尤其是commonsware 提到的那些维护得不是很好。例如,在元信息中使用旋转数据拍摄的图片旋转不好。我找到了这个:https://android-arsenal.com/details/1/3487,它很棒。注意:确保添加带有操作栏主题的活动!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-18
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多