Using canvas and bitmap in Android , how to get this image? -
i new in android. trying draw image(match statistic) , fill image color 10% 100% . tried , image
this code
public class drawview extends view { paint paint = new paint(); public drawview(context context) { super(context); } @override public void ondraw(canvas canvas) { paint.setcolor(color.black); paint.setstrokewidth(3); canvas.drawrect(30, 30, 100, 100, paint); paint.setstrokewidth(0); paint.setcolor(color.gray); canvas.drawrect(33, 60, 97, 97, paint); paint.setcolor(color.white); canvas.drawrect(33, 33, 97, 60, paint); }
any suggestion helpful me. in advance.
i prepare 2 images - filled , not filled (only stroke). having that, load them 2 bitmap
objects , draw that:
float fillprogress = 0.1f; // let's image 10% filled canvas.drawbitmap(onlystroke, 0f, 0f, null); // draw stroke first canvas.save(); canvas.cliprect( 0f, // left getheight() - fillprogress * getheight(), // top getwidth(), // right getheight() // bottom ); canvas.drawbitmap(filled, 0f, 0f, null); // region of filled image specified cliprect drawn on top of onlystroke image canvas.restore();
using 2 images, outlined , filled e.g. below.
the code above following:
- draw outline.
- apply clip (crop) area.
- draw filled shape crop applied.
- remove clip, image desired.
applying different clip sizes, can % of fill require. e.g.
Comments
Post a Comment