gpt4 book ai didi

Java Graphics2D : semi-transparency turns black when using blur filter on shape

转载 作者:行者123 更新时间:2023-11-30 06:15:50 24 4
gpt4 key购买 nike

我正在使用 Java Graphics2D 和 JH Labs 的高斯滤波器来模糊我在透明图像中绘制的一些形状。我注意到形状的模糊边框变成了黑色,更像是阴影。相反,它应该逐渐变得更加透明,让背景颜色透过。

enter image description here

以下是相关代码行:

BufferedImage bi = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();

// Draw shape
g2d.fillRect(x, y, shapeWidth, shapeHeight);

// Apply gaussian filter
BufferedImage bi2 = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
GaussianFilter gaussianFilter = new GaussianFilter();
gaussianFilter.setRadius(10.0f);
gaussianFilter.filter(bi, bi2);
bi = bi2;

知道黑色从何而来,更重要的是,我如何去除它?

最佳答案

我不确定这个问题是否仍然相关。我看到一篇关于模糊的文章,特别是当涉及 alpha channel 时,作者准确地描述了您在问题中提到的现象。作者是这样写的:

The reason is that we've blurred each channel separately, but where the alpha channel is zero (the transparent bits), the red, green and blue channels are zero, or black. When you do the blur, the black gets mixed in with the opaque bits and you get a dark shadow. The solution is to premultiply the image alpha before blurring and unpremultiply it afterwards. Of course, if your images are already premultiplied, you're all set.

您可以看看http://www.jhlabs.com/ip/blurring.html了解更多信息。希望这有帮助

关于Java Graphics2D : semi-transparency turns black when using blur filter on shape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49220816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com