改变java中的图标颜色
所以我正在使用一个可以根据用户的要求更改主题的程序。现在我必须根据主题更改图标颜色。 假设我有一个图标“Cut.png”,因此它将有一个大的透明区域和一些黑色线条,所以我希望这些线条(任何颜色)更改为所需的颜色,并且透明区域相同。我正在尝试使用缓冲图像,我跳过了 0 alpha 的像素,但输出给了我一个完全黑色的图标:(
这是代码的一部分:
BufferedImage buf = ImageIO.read(Image Path);
int red = Color.RED.getRBG();
for(....)//Loop for Row
for(....)//Loop for column
{
Color col = new Color(buf.getRGB(x,y));
if(col.getAlpha() == 0) continue;
buf.setRGB(x,y,red);
}
我的程序完全相同,我希望它应该忽略透明像素应该将彩色像素更改为红色,但生成的输出是全黑的:(
感谢您的帮助:)
So I am working with a program that can change theme as per the user's requirements. Now I have got to change the icon color as per the theme.
Suppose I have an icon "Cut.png" so it will have a large transparent area and some black lines So I want those lines(of any color) to change to the required color and the transparent area to be same. I am trying with a buffered image and I skipped the pixel that has 0 alpha but the output gives me a completely black icon :(
Here is some part of the code :
BufferedImage buf = ImageIO.read(Image Path);
int red = Color.RED.getRBG();
for(....)//Loop for Row
for(....)//Loop for column
{
Color col = new Color(buf.getRGB(x,y));
if(col.getAlpha() == 0) continue;
buf.setRGB(x,y,red);
}
My program is exactly the same and I expect that it should ignore transparent pixels and should change the colored pixels to red but the output produced is completely black :(
Thanks for your help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的目标图像也是透明的
同样,您也可以使用
Graphics
API 直接绘制目标图像,或者您也可以只是对图像进行“着色” ,对于 示例
Make sure your target image is also transparent
Equally, you could also make use of
Graphics
API and paint to the target image directlyOr you could just "tint" the image instead, for example