12-03-2012 02:23 AM
Hi all,
How to calculate RGB values to get custom color and draw that custom color on Bitmap.Give me the suggesions or send the Sample Code.
Thanks & Regards,
Nagarjuna Metla.
12-03-2012 03:42 AM
Check this:
http://sny.no/2011/11/java-hex.html
import java.awt.Color;
public class OperaColor extends Color {
public OperaColor(int r, int g, int b) {
super(r,g,b);
}
/**
* Returns the HEX value representing the colour in the default sRGB ColorModel.
*
* @return the HEX value of the colour in the default sRGB ColorModel
*/
public String getHex() {
return toHex(getRed(), getGreen(), getBlue());
}
/**
* Returns a web browser-friendly HEX value representing the colour in the default sRGB
* ColorModel.
*
* @param r red
* @param g green
* @param b blue
* @return a browser-friendly HEX value
*/
public static String toHex(int r, int g, int b) {
return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
}
private static String toBrowserHexValue(int number) {
StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
while (builder.length() < 2) {
builder.append("0");
}
return builder.toString().toUpperCase();
}
}
12-03-2012 04:00 AM
12-03-2012 04:06 AM
I am not clear on what you are asking here, but here goes.
Most paint packages will give you RGB. There is no need to calculate it.
Colors on BB devices are represented by integers. If you view this color in hex, it will look like
0xAARRGGBB
where AA is the alpha and RGB is as you would expect. So
0x00FF0000
is just full on Red.
This is pretty much what the previous post is telling you.
To paint a color onto a Bitmap, you will get the <Graphics> context, and then use
<graphics>.setColor(<custom color>);
then
<graphics>.drawText(...
or
<graphics>.fillRect(...)
Hopefully that is enough, if not, then can you ask the question a different way to make it clearer.