0

在我的应用程序要求是从图库中选择图像,然后裁剪所选图像并设置为图像视图。以下是我裁剪图像的示例代码。如何使用默认裁剪意图裁剪android棉花糖中的图像?

//call the standard crop action intent (the user device may not support it) 
    Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
    cropIntent.setClassName("com.android.camera", "com.android.camera.CropImage"); 
    //indicate image type and Uri 
    cropIntent.setDataAndType(mImageCaptureUri, "image/*"); 
    //set crop properties 
    cropIntent.putExtra("crop", "true"); 
    //indicate aspect of desired crop 
    cropIntent.putExtra("aspectX", 1); 
    cropIntent.putExtra("aspectY", 1); 
    //indicate output X and Y 
    cropIntent.putExtra("outputX", 256); 
    cropIntent.putExtra("outputY", 256); 
    //retrieve data on return 
    cropIntent.putExtra("return-data", true); 
    cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri); 
    cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); 
    //start the activity - we handle returning in onActivityResult 
    startActivityForResult(cropIntent, PIC_CROP); 

上面的代码工作正常,在下面的Android棉花糖图谋但是Android蜀葵,它是crashing.How解决这个问题?

+0

[Android没有'CROP'' Intent'](https://commonsware.com/blog/2013/01/23/no-android-does-not-have-crop-intent.html)。有很多[可用于Android的图像裁剪库](https://android-arsenal.com/tag/45)。请使用一个。 – CommonsWare

+0

@CommonsWare感谢您的回复,是android棉花糖没有作物意图? – Rajesh

+0

@CommonsWare我试图添加裁剪库,但应用程序大小增加。这就是我寻找默认裁剪的原因 – Rajesh

回答

0

通过裁剪来实现相机和画廊最简单的方法是使用library.in市场上有这么多的第三方库可用,但没有一个适用于所有设备。 有一个图书馆是可用的,它是稳定的传送和几个公司设备。 https://github.com/biokys/cropimage使用此演示。 这是一个非常古老的图书馆,但它在所有不同的设备中都很稳定。