Using canvas and bitmap in Android , how to get this image? -


i new in android. trying draw image(match statistic) enter image description here , fill image color 10% 100% . tried , imageenter image description here

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.

enter image description here enter image description here

the code above following:

  1. draw outline.
  2. apply clip (crop) area.
  3. draw filled shape crop applied.
  4. remove clip, image desired.

enter image description here

applying different clip sizes, can % of fill require. e.g.

enter image description here


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -