954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Represent variable as a int

Hi all. I'm having a problem to represent or use a variable as an int.

Color c = new Color(255, 0, 0);
		int y = c.getRGB();

		for (int v = 0; v < h; v++) {
			for (int u = 0; u < w; u++) {
				int x = image.get(u, v);
				if (x == 255) {
					image.set(u, v, y);
				}
			}
		}


My variable c actually contains the values for a RGB colour. I want to use it as an int so I can set it to the colour I want.

Sunshineserene
Junior Poster
187 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

What do you mean "use it as an int". If you want the 0-255 individual values for the red, green, and blue, then maybe you should be using the getRed(), etc methods, rather than the getRGB method.

P.S. The API docs can be really helpful. Use them.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

though i have not got you properly
but are you looking for

c.getRed();
c.getGreen();
c.getBlue();
c.getRGB();
code learner
Newbie Poster
8 posts since Jan 2011
Reputation Points: 11
Solved Threads: 1
 

The picture is an 8-bit grayscale picture. I need to change the white colour to red colour. How do I do that?

Sunshineserene
Junior Poster
187 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Then why do you need an int? Why not just

if (Color.WHITE.equals(c)) ...
masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: