Fill color on bitmap in android

你。 提交于 2019-11-28 13:05:03

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/20697189/fill-color-on-bitmap-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!