sách gpt4 ăn đã đi

java - bufferedImage.getRGB(x, y) 不产生 alpha

In lại 作者:搜寻专家 更新时间:2023-10-30 19:53:43 25 4
mua khóa gpt4 giày nike

我有一个 BufferedImage Tôi,我想得到 Color来自该图像的某个像素包括 alpha 值。使用 x 坐标标识像素。

这是我尝试过的:

Color c = new Color(i.getRGB(x, y));

出于某种原因,新的颜色对象包含正确的 RGB,但 alpha 丢失了。

我做错了什么?

Cảm ơn trước

câu trả lời hay nhất

您正在使用的单参数 Color 构造函数会丢弃 alpha 信息。改用双参数版本并为 hasalpha đến ĐÚNG VẬY:

Color c = new Color(i.getRGB(x, y), true);

相关Javadoc :

Color(int rgb)

Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

Color(int rgba, boolean hasalpha)

Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

关于java - bufferedImage.getRGB(x, y) 不产生 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10726594/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress