Skip to content Skip to sidebar Skip to footer

Fill Color On Bitmap In Android

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 fi

Solution 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 canvasBitmapbmResult= Bitmap.createBitmap(barWidth, 75,
                Bitmap.Config.ARGB_8888);
        Canvascanvas=newCanvas(bmResult);
        paint.setShader(newLinearGradient(widthToFill, 75, widthToFill, 75,
                0xFF97ca3e, 0xFF284060, TileMode.MIRROR));
        paint.setShader(newLinearGradient(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.

Post a Comment for "Fill Color On Bitmap In Android"