如何读取具有透明度的java BufferedImage中的像素颜色
我正在读取 BufferedImage 中的像素颜色,如下所示:
.....
InputStream is = new BufferedInputStream(conn.getInputStream());
BufferedImage image = ImageIO.read(is);
int color = image.getRGB(x, y);
int red = (colour & 0x00ff0000) >> 16;
int green = (colour & 0x0000ff00) >> 8;
int blue = colour & 0x000000ff;
现在除了具有透明度的 png 之外,这一切都很好。我发现如果 x,y 指的是没有颜色的透明像素,我仍然读取颜色,通常与图像中其他地方使用的颜色相同。
如何检测像素实际上是透明的而不是彩色的?
谢谢
I am reading pixel color in a BufferedImage as follows:
.....
InputStream is = new BufferedInputStream(conn.getInputStream());
BufferedImage image = ImageIO.read(is);
int color = image.getRGB(x, y);
int red = (colour & 0x00ff0000) >> 16;
int green = (colour & 0x0000ff00) >> 8;
int blue = colour & 0x000000ff;
Now this works fine except for png's with transparency. I find that if x,y refer to a transparent pixel with no color, i still read a color, generally the same color as used elsewhere in the image.
How do I detect that the pixel is actually transparent and not colored?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果也是一个范围从 0(完全透明)到 255(完全不透明)的值。
The result is also a value ranging from 0 (completely transparent) to 255 (completely opaque).