Hello. I have a screen like above. By using the sliders, I get red, green, blue. Also, I calculate cyan, magenta, yellow and from red, green, blue for CMYK. My question is that is there any way to show CMYK colour in java like light purple in the picture.
private void stateChanged() {
red= sliderRed.getValue();
green= sliderGreen.getValue();
blue= sliderBlue.getValue();
txt_background.setBackground(new Color(red, green, blue));
}
It looks to me like the java color class, has a constructor for making a color object in cmyk
https://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#Color(java.awt.color.ColorSpace,%20float[],%20float)
and
https://docs.oracle.com/javase/7/docs/api/java/awt/color/ColorSpace.html
So you would end up with something like
Color cmykColorValue = new Color(TYPE_CMYK, [cValue, mValue, yValue, kValue], alpha)
Where alpha is form 0 to 1, and cValue, mValue, yValue, kValue are the corresponding cmyk values.
That should make a new CMYK color object that can be used anywhere a color object can be used.
The correct usage of the Color constructer for CMYK is as follows:
java.awt.Color cmyk = new Color(ColorSpace.getInstance(ColorSpace.TYPE_CMYK), new float [] {cyan,magenta,yellow}, key/alpha);
Related
I don't know how to convert my 3 values (int value for red, green and blue) to one color int value at android.
Color (android.graphics.Color) is an default android class.
int myColor = Color.rgb(red, blue, green)
myView.setBackgroundColor(myColor);
In Android, I am able to set Paint Color to some colors, but for orange, I cannot. Does anyone know if there is an option to set Paint Color to Orange?
Here are some examples of setting Paint Color to other colors beside Orange:
p.setColor(Color.YELLOW);
p.setColor(Color.BLACK);
p.setColor(Color.MAGENTA);
etc.
The orange color has a hex value #FFA500 or Color.rgb(255, 165, 0) so
p.setColor(Color.rgb(255, 165, 0));
or
p.setColor(0xffa500);
see this for more options.
You may create your own orange color, like this:
int orange = Color.rgb(255, 165, 0);
p.setColor(orange);
Hope it helps.
Color is not an enum, it's a class that contains Color constants for the most commonly used colors. You can easily create new custom colors by instantiating Color. You can create a new instance of Color by passing the red, green, and blue values as floats between 0 and 255. Here's a simple example:
Color mycolor = new Color(0, 0, 255);
If the color you're making will simply be brighter or darker than the original color, you can use the brighter or darker methods, like this:
Color brigherColor = mycolor.brighter();
or this:
Color darkerColor = mycolor.darker();
For more information, see the official documentation for Color.
I would write this:
int ORANGE= 0xffa500;
p.setColor(ORANGE);
Is there any way to set the fore ground of for example a label directly by color code rather than the predefined colors that java provides.
For instance :
instead of:
SomeLabel.setForeground(Color.Red);
We do:
SomeLabel.setForeground("240,240,240");
I'm asking this question because I'm setting label colors of the required fields to red when the user skips them, so when I wanna reset their color I can't find the color that I've defined within the predefined colors that java provides.
You could use new Color(240, 240, 240)
Take a look at javax.swing.Color for more details
You can also reset the labels back to their look and feel defaults using UIManager.getColor("Label.foreground"); on most look and feels, for example
SomeLabel.setForeground(new Color(240,240,240));
You can use Color class of java
You can also add Alpha etc. Refer to the Color constructor below
Color(ColorSpace cspace, float[] components, float alpha)
Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.
Color(float r, float g, float b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0).
Color(float r, float g, float b, float a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).
Color(int rgb)
Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
Color(int rgba, boolean hasalpha)
Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
Color(int r, int g, int b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).
Color(int r, int g, int b, int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
I want to load a 8-bit grayscale image using grayscaleImage = ImageIO.read(grayscaleFile). However, the BufferedImage class (which is the type of grayscaleImage) only provides a method getRGB(int x, int y). So, what are the values of color.getRed(), color.getGreen(), color.getBlue() and color.getAlpha() where
Color color = new Color(grayscaleImage.getRGB(x, y), true);
From a first observation, it seems like the 8-bit value, stored in the image file at pixel (x,y), is propagated into the red, green and blue component of color while it's alpha value is fixed at 255.
Can someone confirm this observation?
The value that is obtained with image.getRGB(x,y) is an int that consists of the three color components Red, Green and Blue, each having 8 bit. The Alpha value is fixed as 255 when the image does not contain transparency.
When the image is a grayscale image, the Red, Green and Blue components of this RGB value will be all equal. So you can obtain the "gray" value as
int rgb = image.getRGB(x,y);
// This yields a value between 0 (black)
// and 255 (white) :
int gray = rgb & 0xFF;
That's right. A gray color is just a color with same value in three color's components (red, green, blue). Although you only need one value to determine the color (because red, green and blue components have the same value), at image loading that value is assign to all three color components.
If you get the value for each pixel of the image, you must obtain the same value for three color's components for the same pixel x,y. For alpha component, as it's a grayscale image, is correct it be at 255.
I have the following:
mPaintRefernce.getColor()
How would I retrieve the RGB values in the range of 0-255, so Red = 200, Blue = 120 etc?
That's possible, use the android.graphics.Color class provided by android framework
Color.red(int color); to get the red integer value from color
Color.green(int color); to get the green integer value from color
Color.blue(int color); to get the blue integer value from color
For example, to get the red color.
int red = Color.red(mPaintRefernce.getColor());