Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Change image color programatically

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 139
    Comment on it

    If you want to change the color of an image then you can use the following code :

      public  Bitmap changeColor(Bitmap srcBitmap, int color) {
        Bitmap resBitmap = Bitmap.createBitmap(srcBitmap, 0, 0,  
        srcBitmap.getWidth() - 1, srcBitmap.getHeight() - 1);    
        Paint p = new Paint();
        ColorFilter filter = new LightingColorFilter(color, 1);
        p.setColorFilter(filter);
    
        Canvas canvas = new Canvas(resBitmap);
        canvas.drawBitmap(resBitmap, 0, 0, p);
        return resBitmap;
    }
    

    In the above method you have to send bitmap of an imageview and color code of new color that you want to set on that image.

    Color filter like LightingColorFilter multiplies the RGB channels by one color, and then adds a second color. Then you can sent this color filter on paint object and using canvas you can draw new bitmap on that image.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: