复制图像打水印


        String src = "img.jpg"; // 源文件
        String dec = "img_1.jpg";// 目标文件

        /* * 1. 读取源文件为图像文件 * 2. 给Image对象绘制签名 * 3. 写出Image对象到文件系统 */
        InputStream in = new BufferedInputStream(new FileInputStream(src));
        BufferedImage image = ImageIO.read(in);
        in.close();

        Graphics g = image.getGraphics(); // 绑定画笔
        g.setColor(new Color(0x55ffffff, true));
        g.setFont(new Font("幼圆", 1, 32));
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        g.drawString(sdf.format(date), 30, 30);
        OutputStream out = new BufferedOutputStream(new FileOutputStream(dec));
        ImageIO.write(image, "jpg", out);
        out.close();

你可能感兴趣的:(复制图片,打水印)