John
John

Reputation: 1596

drawCircle painting bitmaps?

Is it possible to paint a drawCircle with an image instead of just a colour? If so, how? If not, is there a way I could make it look like there is? Thanks.

Upvotes: 0

Views: 165

Answers (1)

Kazekage Gaara
Kazekage Gaara

Reputation: 15052

You can draw multiple images onto your Canvas and at desired coordinates, like you can draw your circles. Use the setBounds method properly to assign the exact coordinates where you would want the images to be drawn. Here's a sample code :

public class MyDrawableView extends View {
private Drawable mD1;
private Drawable mD2;

public MyDrawableView(Context context) {
    super(context);

    Resources res = context.getResources();
    mD1 = res.getDrawable(R.drawable.image1);
    //Set image1 bounds using : mD1.setBounds(x, y, x + width, y + height);

    mD2 = res.getDrawable(R.drawable.image2);
    //Set image2 bounds using : mD2.setBounds(a, b, a + width, b + height);
}

protected void onDraw(Canvas canvas) {
    mD1.draw(canvas);
    mD2.draw(canvas);
}
}

Upvotes: 1

Related Questions