改变java中透明像素的颜色 [英] change color of transparent pixel in java

查看:497
本文介绍了改变java中透明像素的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我可以将另一个图像的像素应用到pg到m的源图像像素。但问题是我失去了渐变或褪色效果。

Now i am able to apply pixel of another image to source image pixel of pg to m. but problem is that i m loosing gradient or fading effect.

     public static void main(String[] args){
        try {
            BufferedImage image = ImageIO.read(new File("c:\\m.png"));
            BufferedImage patt = ImageIO.read(new File("c:\\pg.png"));

            int f = 0;
            int t = 0;
            int n = 0;
            BufferedImage bff = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
            for (int y = 0; y < image.getHeight(); ++y) {
                for (int x = 0; x < image.getWidth(); ++x) {
                    int argb = image.getRGB(x, y);
                    int nrg = patt.getRGB(x, y);

                    if(((argb>>24) & 0xff) == 0) {
                                bff.setRGB(x, y, (255<<24));
                    } else {
                                bff.setRGB(x, y, nrg);
                    }                               
                }
            }
            System.out.println("Trans : " + t + " Normal : " + n);
            File outputfile = new File("c://imagetest.png");
            ImageIO.write(bff, "png", outputfile);
        } catch (IOException ex) {

        }

}

谢谢。

推荐答案

0xff000000 是opaque black, 0x00000000 完全透明。

0xff000000 is opaque black, 0x00000000 is completely transparent.

什么是 0 (你选择的颜色)?

What is 0 (the colour you chose)?

是的,它是透明的。

试试 0xff000000 甚至更好: argb ^ 0xff000000 ,只改变了透明度。

Try 0xff000000 or even better: argb ^ 0xff000000, which just changes the transparency, instead.

                if(((argb>>24) & 0xff) == 0) {
                            bff.setRGB(x, y, argb ^ 0xff000000);
                } else {
                            bff.setRGB(x, y, argb);
                }                               

这篇关于改变java中透明像素的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆