将RGB值转换为Integer [英] Convert RGB values to Integer
本文介绍了将RGB值转换为Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,在 BufferedImage
中,您会收到一个整数,其中包含RGB值。到目前为止,我使用以下内容从中获取RGB值:
So in a BufferedImage
, you receive a single integer that has the RGB values represented in it. So far I use the following to get the RGB values from it:
// rgbs is an array of integers, every single integer represents the
// RGB values combined in some way
int r = (int) ((Math.pow(256,3) + rgbs[k]) / 65536);
int g = (int) (((Math.pow(256,3) + rgbs[k]) / 256 ) % 256 );
int b = (int) ((Math.pow(256,3) + rgbs[k]) % 256);
到目前为止,它有效。
我需要做的是弄清楚如何获得整数所以我可以使用 BufferedImage.setRGB()
,因为它采用相同的类型它给了我的数据。
What I need to do is figure out how to get an integer so I can use BufferedImage.setRGB()
, because that takes the same type of data it gave me.
推荐答案
我认为代码类似于:
int rgb = red;
rgb = (rgb << 8) + green;
rgb = (rgb << 8) + blue;
此外,我相信您可以使用以下方式获取个别价值:
Also, I believe you can get the individual values using:
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
这篇关于将RGB值转换为Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文