gpt4 book ai didi

java - 想要剪切 Canvas 圆圈的背景图像

转载 作者:行者123 更新时间:2023-12-02 06:22:22 26 4
gpt4 key购买 nike

想要剪切 Canvas 圆圈的背景图像

canvas.drawBitmap(background_image, 0, 0, null);            
FaceDetector.Face face = faces[0];
tmp_paint.setColor(Color.RED);
`face.getMidPoint(tmp_point);
canvas.drawCircle(tmp_point.x, tmp_point.y, face.eyesDistance(), tmp_paint);

最佳答案

您可以使用以下功能:

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
int targetWidth = 125;
int targetHeight = 125;

Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
targetHeight, Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(targetBitmap);
Path path = new Path();
path.addCircle(
((float) targetWidth - 1) / 2,
((float) targetHeight - 1) / 2,
(Math.min(((float) targetWidth), ((float) targetHeight)) / 2),
Path.Direction.CCW);
canvas.clipPath(path);
Bitmap sourceBitmap = scaleBitmapImage;
canvas.drawBitmap(
sourceBitmap,
new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()),
new Rect(0, 0, targetWidth, targetHeight),
p);
return targetBitmap;
}

有关更多详细信息,请查看:http://www.androiddevelopersolutions.com/2012/09/crop-image-in-circular-shape-in-android.html

关于java - 想要剪切 Canvas 圆圈的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20904856/

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