如何使用裁剪选项直接打开图像

时间:2015-07-20 06:12:33

标签: android resize-crop

我想剪裁图片,我可以实现这一点。

我的代码是

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。

使用此代码打开警报以选择应用程序以选择图像,我想知道我已经通过图像路径然后为什么要求选择应用程序打开图像,当我选择应用程序(通过图库)然后我必须选择从画廊到作物的图像。

我想要一个解决方案,使用裁剪选项打开我的图像,而无需选择要打开的应用程序?

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

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

使用本地作物不是好的解决方案,因为每种作物的行为都不同。我遇到了一些错误,因为无法保存文件,长宽比不正确,也许还有其他错误 我认为从图库中挑选照片后使用自定义裁剪库的最佳解决方案。
有一些很好的库包含https://github.com/jdamcd/android-crophttps://github.com/lvillani/android-cropimagehttps://github.com/edmodo/cropper

等示例