I have searched EVERYWHERE for an answer to this.
I am trying to work out how to draw a custom shape made in xml to a bitmap or to a canvas.
This is my simple xml code for a rectangle.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#f0f000" />
<stroke android:width="3dp" android:color="#ff0000" />
</shape>
Then here, I am trying to simply get the shape and put it on a bitmap, then draw that bitmap to the canvas?
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.shape);
canvas.drawBitmap(myBitmap, canvas.getHeight() /2, canvas.getWidth()/2, p);
If anyone can help I would very much appreciate it.
It’s a drawable… try this:
NB: Obviously you can do the getDrawable() bit just once, rather than on every draw().