当前位置: 移动技术网 > IT编程>开发语言>Java > java 图片加水印实例代码

java 图片加水印实例代码

2019年07月22日  | 移动技术网IT编程  | 我要评论

食人大蛇王,3088港币,赵本山小品相亲下载

复制代码 代码如下:

try {
            string targetimg = "d:/blue hills.jpg";
//          string pressimg = "d:/20130311220300.jpg";
            string pressimg = "d:/html_original.jpg";

            file f1 = new file(targetimg);
            image src = imageio.read(f1);
            int width = src.getwidth(null);
            int height = src.getheight(null);

            bufferedimage image = new bufferedimage(width, height, bufferedimage.type_int_rgb);
            graphics g =  image.creategraphics();
            g.drawimage(src, 0, 0, width, height, null);

            file f2 = new file(pressimg);
            image src_pao = imageio.read(f2);
            int width_pao = src_pao.getwidth(null);
            int height_pao = src_pao.getheight(null);
            g.drawimage(src_pao, (width-+width_pao)/2, (height-height_pao)/2,width_pao,height_pao, null);
//          g.drawimage(src_pao, 100, 100,width,height, null);

            g.dispose();
            fileoutputstream out = new fileoutputstream(targetimg);
            jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
            encoder.encode(image);
            out.close();
            system.out.println("水印添加成功!!");

        } catch (exception e) {
            // todo: handle exception
            system.out.println("水印添加失败!!");
            e.printstacktrace();
        }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网