如果我有一个Color
对象,如何将其RGB值转换为十六进制整数?我一直在寻找年龄,所有我发现的是“十六进制到RGB”,或者它不返回一个整数值,或其他我不想要的东西。将RGB转换为十六进制
我希望它返回十六进制值作为int
值,而不是字符串或其他任何东西。谁能帮忙?
这里是我的代码,我需要一个颜色转换为十六进制,使用别人的答案,尝试将其转换:
public static void loadImageGraphics(BufferedImage image, int x, int y, int width, int height) {
for(int yy = 0; yy < height; yy++) {
for(int xx = 0; xx < width; xx++) {
Color c = new Color(image.getRGB(xx, yy));
pixels[x + y * width] = c.getRed() * (0xFF)^2 + c.getGreen() * 0xFF + c.getBlue();
}
}
}
谢谢!
一个整数,仅仅是一个值。将其转换为字符串时,它只会变成十六进制表示形式。 – Henry
其他解决方案这里http://stackoverflow.com/questions/3607858/how-to-convert-a-rgb-color-value-to-an-hexadecimal-value-in-java – gowtham