Fill color on bitmap in android

前端 未结 1 1664
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 13:13

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 requirem

相关标签:
1条回答
  • 2020-12-22 14:00

    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.

    0 讨论(0)
提交回复
热议问题