Streamer
Streamer

Reputation: 51

Want to Cut background image of canvas circle

Want to Cut background image of canvas circle

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

Upvotes: 0

Views: 589

Answers (1)

Virag Brahme
Virag Brahme

Reputation: 2062

You can use the following function:

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

For more details check this : http://www.androiddevelopersolutions.com/2012/09/crop-image-in-circular-shape-in-android.html

Upvotes: 2

Related Questions