安卓4.3作物画廊结果code取消 [英] Android 4.3 crop gallery resultCode Cancel

查看:172
本文介绍了安卓4.3作物画廊结果code取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Galaxy Nexus的现在在Android 4.3上运行,允许我用这个新版本的测试我的应用程序。除了种植一切似乎罚款。

My Galaxy Nexus is now running on Android 4.3 allowing me to test my application with this new version. Everything seems fine except cropping.

我有一个使用相机拍摄图片,然后通过画廊的应用程序裁剪图像的应用程序。

I have an application that uses the camera to take picture and then crop the image through the gallery app.

我也可以选择从画廊的图片,之后裁剪。 由于Android 4.3,画廊应用程序更改。

I am also able to choose a picture from the gallery and crop it after. Since Android 4.3, the gallery application changed.

如果我采取与照相机API图片,然后问画廊裁剪它在我的 onActivityResult方法的结果code设置为0 (意为取消),而我点击从作物视图保存。

If i take a picture with the camera api and then ask the gallery to crop it in my onActivityResult method the resultCode is set to 0 (meaning cancel) whereas i clicked on "Save" from the crop view.

但是,如果我选择从库中的图片和裁剪一切正常,结果code参数设置为-1。 我所说的同样的方法来裁切照片在两种情况下。

But if i choose a picture from the gallery and crop it everything works, the resultCode parameter is set to -1. I call the same method to crop the picture in both cases.

我有我的手机上下载快(替代画廊应用程序),有了它一切正常!

I have quickpic (an alternative to the gallery app) on my phone, with it everything works !

private void performCrop(Uri picUri) {
    try {
        int aspectX = 750;
        int aspectY = 1011;

        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(picUri, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("scale", "true");
        intent.putExtra("aspectX", aspectX);
        intent.putExtra("aspectY", aspectY);
        intent.putExtra("scaleUpIfNeeded", true);

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

样样精制作的Andr​​oid 4.2.2。 谢谢您的帮助!

Everything worked fine on Android 4.2.2. Thank you for your help !

推荐答案

你刚使用这样一个库认为:

Have you considered just using a library like this one:

https://github.com/biokys/cropimage

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

}

这篇关于安卓4.3作物画廊结果code取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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