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.

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.

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

c.getRed();
c.getGreen();
c.getBlue();
c.getRGB();

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

Then why do you need an int? Why not just

if (Color.WHITE.equals(c)) ...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.