How to fill a star with partially in android? -
to see above picture. sample code below
`protected void ondraw(canvas canvas) { mid = getwidth()/2; int a=100,b=100; min = math.min(a, b); fat = min / 17; half = min / 2; rad = 5; mid = mid - half;
     paint = new paint();     paint.setcolor(color.blue);     paint.setstyle(paint.style.stroke);     path path = new path();     path.reset();     paint.setstyle(paint.style.fill);    // top left     path.moveto(half * 0.5f, half * 0.84f);   // top right     path.lineto(half * 1.5f, half * 0.84f);   // bottom left     path.lineto(half * 0.68f, half * 1.45f);   // top tip     path.lineto(half * 1.0f, half * 0.5f);  // bottom right     path.lineto(half * 1.32f, half * 1.45f);   // top left     path.lineto(half * 0.5f, half * 0.84f);      path.close();  canvas.drawpath(path, paint);     super.ondraw(canvas);  }`    my question how partially fill star in android?
i want fill option not half fill star.
and also, if consider full star length 100%.
and have fill star length of 20% or have fill star length of 50% or have fill star length of 70%.
any fill values fill star.
your path object here 'outline' of star. if want paint it, set style fill , stroke. can't partially paint it. need create path object , set paint fill , draw it. ideally draw outline , fill separately. 
it's simple. have done half of it. can reuse calculation did outline path fill path.
update: if rating kind of thing, need dynamically increase or decrease filling. if that's case. draw fill rectangle, , clip using star outline. need increase or decrease width of rectangle.
more info here : how mask out simple region when painting in android?
update: if it's partial picture want, have create bitmap of picture , draw using drawbitmap(). clip region make it's partially filled, using clipregion().
Comments
Post a Comment