java - 在java中更改bufferedImage像素

标签 java image java-8 bufferedimage bitwise-operators

我有一个小问题。 我有一个 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/

相关文章:

java - Swing Worker - 传递许多参数

java - 从哪里开始创建Minecraft客户端模块

objective-c - 如何从源服务器 URL 生成缩略图?

java - 为什么 SimpleDateFormat::format(Long) 适用于 Java?

java - 在处理不可变对象(immutable对象)时,如何最好地返回带有修改字段的副本?

java - 如何获取类中所有方法的方法引用(Java)?

java - 如何在日期数据类型中存储字符串数据类型值

java - MergeSort - 实现

wpf - 使用 XAML 绑定(bind)到添加到 resx 文件的图像的图像

CSS 目标链接的图像以及将多张图像放在一行中的最佳方法