com.android.camera.action.CROP 是否不适用于 Android jelly bean 4.3? [英] Is com.android.camera.action.CROP not available for Android jelly bean 4.3?

查看:11
本文介绍了com.android.camera.action.CROP 是否不适用于 Android jelly bean 4.3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was using com.android.camera.action.CROP for cropping after taking pic using camera.

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

Below was my code which used to work earlier before 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 裁剪操作会将您带到图库(因为图库默认使用裁剪),因此这种裁剪方法失败(照片未保存到图库).

But now since android crop action takes you to gallery(because gallery is default with crop), this cropping method fails(photo is not saved to gallery).

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

Does any one knows a way out of this issue. Where I can use the crop on the photo taken from camera

推荐答案

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

Copying the answer from a similar question asked earlier..

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

Have you considered just using a library like this one:

GitHubLink

我发现 com.android.camera.action.CROP 有时会因手机而异,而且并非始终可用,因此如果您希望发布它,它可能会给您带来一些问题.

I find the com.android.camera.action.CROP can sometimes behave differently from phone to phone and is not always available, so it could cause some problems for you anyway if you are looking to release it.

更新:

我已经用 Android 4.3 测试了上面的库,它没有问题.您只需要将库添加到您的项目中.

I have tested the above library with Android 4.3 and it works with no problem. You just need to add the library to your project.

然后您可以以非常相似的方式编写您的方法:

You can then write your method in a very similar way:

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

这篇关于com.android.camera.action.CROP 是否不适用于 Android jelly bean 4.3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆