gpt4 book ai didi

android - 圆形裁剪而不是矩形裁剪

转载 作者:行者123 更新时间:2023-11-29 00:26:23 27 4
gpt4 key购买 nike

我知道如何创建一个圆形位图,如以下示例所示

Crop square image to circle - Programmatically

Cropping circular area from bitmap in Android

在上面的例子中,如何使图像适合圆形 View ,, 我搜索了很多,发现很大的是 ,,,,, 在大多数代码中,他们一直在使用以下函数来裁剪图像

 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();
}
}

其实矩形裁剪是通过上面的代码实现的,,,我想用上面的函数进行圆形裁剪,,,请大家帮忙,,,

最佳答案

您可以查看类似链接 Cirular Crop

尝试如下圆形裁剪:

image/* 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找到的

关于android - 圆形裁剪而不是矩形裁剪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19087665/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com