Fill color on bitmap in android

2.6k Views Asked by At

How i can fill color on image(i.e fuel image) in specific area as per Seek bar progress.

i have tried following solution but it is not helpful much as per my requirement.

please find below image for more reference.

enter image description here

1

There are 1 best solutions below

5
On

You could also draw a bitmap on top of the layer you have. Simply add a bitmap with the same dimensions as the bar (or whatever you have) you want to have coloured in. Then add the colours and say how far it should colour in the bar.

Example:

// making our bitmap and canvas
        Bitmap bmResult = Bitmap.createBitmap(barWidth, 75,
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmResult);
        paint.setShader(new LinearGradient(widthToFill, 75, widthToFill, 75,
                0xFF97ca3e, 0xFF284060, TileMode.MIRROR));
        paint.setShader(new LinearGradient(widthToFill, 75, widthToFill, 75,
                0xFF97ca3e, 0xFF284060, TileMode.CLAMP));
        paint.setARGB(188, 164, 120, 130);
        canvas.drawRect(0, 0, widthToFill, 75, paint);

widthToFill would be a variable with the value of how much you want to draw in. You could also draw this dynamic by getting the screenwidth and calculating the percentages.

Best of luck.