想要剪切画布圈的背景图片

Posted

技术标签:

【中文标题】想要剪切画布圈的背景图片【英文标题】:Want to Cut background image of canvas circle 【发布时间】:2014-01-03 13:33:56 【问题描述】:

想要剪切画布圆圈的背景图片

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

【问题讨论】:

【参考方案1】:

您可以使用以下功能:

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

【讨论】:

new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap .getHeight()), new Rect(0, 0, targetWidth, targetHeight), p)中的“p”是什么;这是一条路吗?????? p 是绘画的对象

以上是关于想要剪切画布圈的背景图片的主要内容,如果未能解决你的问题,请参考以下文章

ps中裁切的快捷键

delphi实现图片剪切的功能?急啊!!!

canvas中的drawImage

设置织物js画布的100%高度和宽度

canvas使用图像(绘制图、图像平铺、图像剪裁、像素处理、绘制文字)

JS获取剪切板内容