zoukankan      html  css  js  c++  java
  • Java给图片加水印

    /**
    * 方法描述:<b>给图片增加水印.</b></br>
    * 备 注: 在图片上写字符串
    * 创 建 人: bo.gaobo</br>
    * 创建日期: 2012-09-07</br>
    * @param originalUrl 原始图片存储路径
    * @param oldImg 原图片
    * @param str 增加的字符串
    * @param xLocation x坐标
    * @param yLocation y坐标
    * @param fontColor 颜色
    * @param fontSize 字号
    * @param typeFace 字体
    * @param fileType 文件类型
    */
    public static BufferedImage addStringToImg(String originalUrl, BufferedImage oldImg,String str,int xLocation,int yLocation, Color fontColor, int fontSize, String typeFace, String fileType) throws IOException{
    FileOutputStream output = new FileOutputStream(originalUrl);
    BufferedImage buffImg = oldImg;
    Graphics2D g = buffImg.createGraphics();
    g = buffImg.createGraphics();
    g.drawImage(buffImg, null, 0, 0);
    g.setColor(fontColor); //设置字体颜色
    g.setFont(new Font(typeFace, Font.PLAIN, fontSize)); //设置字体和字号
    g.drawString(str, xLocation, yLocation); //把字符串放在对应的坐标处
    g.dispose();
    ImageIO.write(buffImg, fileType, output); //设置文件类型
    output.close();
    return buffImg;
    }

  • 相关阅读:
    Pascal's Triangle II
    Pascal's Triangle
    Path Sum II
    Path Sum
    plusOne
    Divide Two Integers
    64. ZigZag Conversion
    63. Swap Nodes in Pairs && Rotate List && Remove Nth Node From End of List
    62. Divide Two Integers
    61. Unique Paths && Unique Paths II
  • 原文地址:https://www.cnblogs.com/loveLearning/p/2682215.html
Copyright © 2011-2022 走看看