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使用此演示。 這是一個非常古老的圖書館,但它在所有不同的設備中都很穩定。