0

我想裁剪图像,我能够实现这一点。

我的代码是

Intent cropIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);         
        cropIntent.setDataAndType(fileUri, "image/*");
        // set crop properties
        cropIntent.putExtra("crop", "true");    
        cropIntent.putExtra("return-data", true);       
        startActivityForResult(cropIntent, CROP_PIC);

其中fileUri包含我要从图库中裁剪的图像路径的 URI。

使用此代码会打开一个警报以选择应用程序以选择图像,我想知道虽然我已经通过了图像路径,但为什么它要求选择应用程序以打开图像,当我选择应用程序(通过图库)时,我必须从图库中选择图像作物。

我想要一个解决方案,使用该解决方案可以使用裁剪选项打开我的图像,而不要求选择要打开的应用程序?

可能吗?请帮助我实现它...

4

2 回答 2

1

试试这个:

     String filename = "image.png";
     String path = "/mnt/sdcard/" + filename;
     File f = new File(path);  //  
     Uri imgUri= Uri.fromFile(f);  
     Intent intent = new Intent("com.android.camera.action.CROP");  
            intent.setDataAndType(imgUri, "image/*");  
            intent.putExtra("crop", "true");  
            intent.putExtra("aspectX", 1);  
            intent.putExtra("aspectY", 1);  
            intent.putExtra("outputX", 50);  
            intent.putExtra("outputY", 50);  
            intent.putExtra("return-data", true);
            startActivityForResult(intent, 1);
于 2015-07-20T06:34:57.100 回答
0

Using the native crop is not good solution, because the behavior of each crop is different. I came across some errors as it is not possible to save a file, is not correct aspect ratio, maybe there are also other.
I think the best solution to use custom crop library after pick photo from gallery.
There are some good libraries with examples like https://github.com/jdamcd/android-crop or https://github.com/lvillani/android-cropimage or https://github.com/edmodo/cropper

于 2015-07-20T07:29:28.397 回答