在 Java2D 中使用 ColorConvertOp 时,有没有办法设置默认颜色透明度?
我正在将具有透明度的图像转换为不具有透明度的色彩空间。我想为透明区域设置背景颜色。现在,当我将其转换时,最终图像中任何透明区域都会变成黑色。当我在 ColorSpace 之间进行转换时,有办法做到这一点吗?这是我用来在颜色空间之间进行转换的代码:
public BufferedImage convertColorspace( BufferedImage source, int newType) {
BufferedImage destination = new BufferedImage( source.getWidth(), source.getHeight(), newType);
ColorConvertOp colorConvertOp = new ColorConvertOp(null);
colorConvertOp.filter(source, destination);
return destination;
}
// here is how its used
BufferedImage converted = convertColorspace(combinedImage, BufferedImage.TYPE_3BYTE_BGR);
我正在从 BufferedImage.TYPE_4BYTE_ARGB 转换为 BufferedImage.TYPE_3BYTE_BGR。
I'm converting an image with transparency in it into a Colorspace that doesn't have transparency. I'd like to set a background color for the transparent areas. Right now when I convert it any area that is transparent turns to black in the final image. Is there a way to do that while I'm converting between ColorSpaces? Here is my code I use to convert between color spaces:
public BufferedImage convertColorspace( BufferedImage source, int newType) {
BufferedImage destination = new BufferedImage( source.getWidth(), source.getHeight(), newType);
ColorConvertOp colorConvertOp = new ColorConvertOp(null);
colorConvertOp.filter(source, destination);
return destination;
}
// here is how its used
BufferedImage converted = convertColorspace(combinedImage, BufferedImage.TYPE_3BYTE_BGR);
I'm converting from BufferedImage.TYPE_4BYTE_ARGB to BufferedImage.TYPE_3BYTE_BGR.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
然后使用
temp
而不是source
调用colorConvertOp.filter
。How about:
Then call
colorConvertOp.filter
withtemp
instead ofsource
.