我有一个小问题。 我有一个 BufferedImage,其中的像素具有 RGB 值。 此代码用于从 R、G、B、A 值创建 RGB 值。
private int getRGB(int r, int g, int b, int a){
return (a << 24) | (r << 16) | (g << 8) | b;
}
第一个问题是,我如何从像素中获取 R、G、B、A 值,因为像素 RGB 将返回上面代码生成的数字。
如果我有这些值,我可以将 2 个像素放在彼此的顶部,以便计算新值还是我必须手动执行此操作? 通过自动计算,您可以想到 Java 2D,当您将 2 个传输对象放在顶部时,它会合并颜色。
非常感谢。
最佳答案
The first question is, how can i get the R, G, B, A values from a Pixel, because the pixel RGB will return the number that is generated by the code above.
您可以按如下方式反转该过程:
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF;
int g = (argb >> 8) & 0xFF;
int b = (argb >> 0) & 0xFF;
And if I have those values, can I put 2 pixels on top of each other so it calculates the new values or do I have to do that by manual? With automatic calculation you can think of Java 2D when you put 2 transport things on top it will merge the colors.
您将需要手动执行此操作(或调用每个像素的实用方法),因为您需要决定如何合成颜色,例如您可以使用最大值、总和、平均值等像素值。
关于java - 在java中更改bufferedImage像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29365042/