65.9K
CodeProject is changing. Read more.
Home

Change The Image Color in Android

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Mar 22, 2013

CPOL
viewsIcon

15882

This Artical shows that how we can change the color of any image throw Bitmap

Introduction

In Android Programming Language Graphics provide very powerful functions by the help of which we can do many attractive work we can also design low level game for fun,So in this page we learn how we can change the color of any Image.

Background 

By using this example we can design a application that change the color of image

Using the code

Small line of code given below use to change the color of image,here only single image is use that's name is new2

                         Bitmap b=BitmapFactory.decodeResource(getResources(),R.drawable.new2);
			 can.drawBitmap(b, 10, 10,null);
			 
			 ColorFilter f=new LightingColorFilter(0x00FF00, 0x0000FF);
			 p.setColorFilter(f);
			 can.drawBitmap(b, 100, 100,p);
			 ColorFilter f1=new LightingColorFilter(0x00FF00, 0xFF00FF);
			 p.setColorFilter(f1);
			 can.drawBitmap(b, 0, 200,p);
   

This code should be written within onDraw() method of Graphics.

Points of Interest 

In this code on of the important thing that is interest which is ColorFilter which define which color will display.