[英]Canvas crop image Android
You can do that using Android PorterDuffMode Here is the code您可以使用 Android PorterDuffMode 来做到这一点 这是代码
private fun crop(bitmapImage: Bitmap): Bitmap {
val bitmap = Bitmap.createBitmap(
bitmapImage.width,
bitmapImage.height,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
canvas.drawCircle(100.0f, 100.0f, 50.0f, paint)
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)
canvas.drawBitmap(bitmapImage, 0.0f, 0.0f, paint)
return bitmap
}
you can change the circle pivot and radius to achieve your result, If you pass the bitmap of the image, it will return the bitmap and you can save to file您可以更改圆的枢轴和半径以实现您的结果,如果您传递图像的位图,它将返回位图,您可以保存到文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.