2013-09-30 62 views
2

我知道如何瞭解創建一個圓形的位圖將其示出在下面的實施例圓形作物而不是矩形作物

Crop square image to circle - Programmatically

Cropping circular area from bitmap in Android

在上述例子中如何將圖像裝入圓形圖, , 我搜了很多,我發現大的是,,,,,在大多數代碼中,他們一直在使用以下功能來裁剪圖像

private void performCrop() 
{ 
    // take care of exceptions 
    try { 
    // call the standard crop action intent (the user device may not 
    // support it) 
    Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
    // indicate image type and Uri 
    cropIntent.setDataAndType(picUri, "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); 
    // start the activity - we handle returning in onActivityResult 
    startActivityForResult(cropIntent, PIC_CROP); 
    } 
    // respond to users whose devices do not support the crop action 
    catch (ActivityNotFoundException anfe) { 
    // display an error message 
    String errorMessage = "Whoops - your device doesn't support the crop action!"; 
    Toast toast = Toast 
    .makeText(this, errorMessage, Toast.LENGTH_SHORT); 
    toast.show(); 
    } 
} 

其實矩形裁剪通過上述代碼實現了,,,我想使用圓形裁剪上述功能,,,請提供您的幫助,,,

回答

3

您可以檢查出的類似鏈接Cirular Crop

試試如下爲圓形作物:

EXTA選項表用於圖像/ *作物:

SetExtra DataType Description  

    crop  String Signals the crop feature 
    aspectX int Aspect Ratio 
    aspectY int Aspect Ratio 
    outputX int width of output created from this Intent 
    outputY int width of output created from this Intent 
    scale  boolean  should it scale 
    return-data boolean Return the bitmap with Action=inline-data by using the data 
    data Parcelable Bitmap to process, you may provide it a bitmap (not tested) 
    circleCrop String if this string is not null, it will provide some circular cr 
    MediaStore.EXTRA_OUTPUT ("output") URI Set this URi to a File:///, see example code 
try { 
// Launch picker to choose photo for selected contact 
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); 
intent.setType("image/*"); 
intent.putExtra("crop", "true"); 
intent.putExtra("aspectX", aspectX); 
intent.putExtra("aspectY", aspectY); 
intent.putExtra("outputX", outputX); 
intent.putExtra("outputY", outputY); 
intent.putExtra("scale", scale); 
intent.putExtra("return-data", return_data); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri()); 
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); 
intent.putExtra("noFaceDetection",!faceDetection); // lol, negative boolean noFaceDetection 

if (circleCrop) { 
intent.putExtra("circleCrop", true); 
} 

startActivityForResult(intent, PHOTO_PICKED); 
} catch (ActivityNotFoundException e) { 
Toast.makeText(thiz, R.string.photoPickerNotFoundText, Toast.LENGTH_LONG).show(); 
} 

我發現它從HERE

+0

u必須提供的答案就是上面我所提到的,先生的問題,這些例子最終實現圓形圖像,但無法提供裁剪機能的研究裏面的圓形作物,對不起 –

+0

@GowthamRayar結帳我更新的答案。 – GrIsHu