Android Killer
Android Killer

Reputation: 18489

How to make a circular image covered with different color

I have an circular image.It is displaying in list view.In every item of list view there is one text and this image.This circular image has one color.How can i make some portion of this image covered with any other color.Any help will be appreciated.

Upvotes: 0

Views: 450

Answers (2)

Durgpal Singh
Durgpal Singh

Reputation: 11953

If you want to change background colour of image at run time ......

then use this simple code...

it working nice....

 final ImageView image=(ImageView)findViewById(R.id.image_view);

   int number1=(int) (Math.random()*255);
   int number2=(int) (Math.random()*255);
   int number3=(int) (Math.random()*255);

   int image_colour=android.graphics.Color.rgb(number1, number2, number3);
   image.setColorFilter(image_colour);

Upvotes: 0

John J Smith
John J Smith

Reputation: 11923

Make sure the image you have is on a transparent background. Then, cutout a portion of the image which you wish to change colour. Then, in your program call setBackgroundColor(int myColor) and the colour you set will show through.

Edit: Using Photoshop, or your favourite image editing program, prepare your image by ensuring it is on a transparent background. Then cutout the part which you want to change colour. Save the image in your drawable-hdpi folder in your Android project. Then, set the background colour to the colour you want and it will show through the cutout e.g.

ImageView icon = new ImageView(context);
icon.setId(1);      
icon.setImageResource(R.drawable.paint_splat);      
icon.setBackgroundColor(pickedColour);

In the example above, my paint_splat image shown below:

enter image description here

the white areas are not white - they are translucent. If you don't know how to do this, you need to read up on image editing in whatever image editing program you will use. Then the last call :

icon.setBackgroundColor(pickedColour);

Sets the background colour but this can only be seen through the translucent part of the image and so it changes the colour, in my case, of the paint splats.

Also, if the colour you use for the foregound matches the main screen colour of your application, in my case the splat image has a black colour foreground and my Android app has a black screen, then ONLY the coloured paint splat is visible so it looks like the whole image is changing colour.

Upvotes: 1

Related Questions