如何将 BufferedImage 转换为某种颜色?
具体来说,我的图像都是透明的纯黑色。我想在绘制图像时为图像分配任意颜色,以便黑色区域更改为新颜色。
我尝试使用 RGBImageFilter ,它只返回我想要的颜色,但出了问题并且根本没有绘制任何内容。 (ColourFilter 扩展了 RGBImageFilter 并且仅返回其 filterRGB() 方法中设置的颜色。)
BufferedImage tileImage = _tiles.get( tileID );
ColourFilter cFilt = new ColourFilter();
cFilt.setColour( colour );
FilteredImageSource filteredSrc = new FilteredImageSource( tileImage.getSource(), cFilt );
Image finalImage = Toolkit.getDefaultToolkit().createImage(filteredSrc);
bufferGraphics2D.drawImage(finalImage.....
Speicifically I have images that are all solid black on transparent. I want to assign an abritrary colour to the images when they are drawn so that the black areas are changed to the new colour.
I tried using a RGBImageFilter that just returned the colour I want but something's going wrong and nothing is being drawn at all. (ColourFilter extends RGBImageFilter and just returns the set colour in it's filterRGB() method.)
BufferedImage tileImage = _tiles.get( tileID );
ColourFilter cFilt = new ColourFilter();
cFilt.setColour( colour );
FilteredImageSource filteredSrc = new FilteredImageSource( tileImage.getSource(), cFilt );
Image finalImage = Toolkit.getDefaultToolkit().createImage(filteredSrc);
bufferGraphics2D.drawImage(finalImage.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 AlphaComposites,特别是 DST_IN:
Look at AlphaComposites, particularly DST_IN:
我不是 100% 确定你想要做什么,但是图像过滤器应该能够做我认为你想要做的事情。例如,
I'm not 100% sure what you're trying to do, but image filters and should be able to do what I think you are trying to do. For e.g.,