要剪切画布圆的背景图像

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

07-24 09:48
查看更多