程序包 org.anyline.util

类 ImgUtil

java.lang.Object
org.anyline.util.ImgUtil

public class ImgUtil extends Object
图片处理工具类:
功能:缩放图像、切割图像、图像类型转换、彩色转黑白、文字水印、图片水印等
  • 构造器详细资料

    • ImgUtil

      public ImgUtil()
  • 方法详细资料

    • scale

      public static void scale(File src, File tar, float scale)
      缩放图像(按比例缩放)
      参数:
      src - 源图像文件地址
      tar - 缩放后的图像地址
      scale - 缩放比例
    • scale

      public static void scale(File src, File tar, String format, int width, int height, boolean fill)
      缩放图像(按高度和宽度缩放)
      参数:
      src - 源图像文件地址
      tar - 缩放后的图像地址
      format - 格式
      height - 缩放后的高度
      width - 缩放后的宽度
      fill - 比例不对时是否需要补白:true为补白; false为不补白;
    • scale

      public static void scale(File src, File tar, String format, int width, int height)
    • scale

      public static void scale(File src, File tar, int width, int height, boolean fill)
    • cut

      public static void cut(File src, File tar, int x, int y, int w, int h)
      图像切割(按指定起点坐标和宽高切割)
      参数:
      src - 源图像地址
      tar - 切片后的图像地址
      x - 目标切片起点坐标X
      y - 目标切片起点坐标Y
      w - 目标切片宽度
      h - 目标切片高度
    • cut

      public static void cut(File src, File dir, int rows, int cols)
      图像切割(指定切片的行数和列数)
      参数:
      src - 源图像地址
      dir - 切片目标文件夹
      rows - 目标切片行数.默认2, 必须是范围 [1, 20] 之内
      cols - 目标切片列数.默认2, 必须是范围 [1, 20] 之内
    • getSizeScale

      public static float getSizeScale(File file)
    • cut3

      public static final void cut3(File src, File dir, int width, int height)
      图像切割(指定切片的宽度和高度)
      参数:
      src - 源图像地址
      dir - 切片目标文件夹
      width - 目标切片宽度.默认200
      height - 目标切片高度.默认150
    • convert

      public static final void convert(File src, String format, String dest)
      图像类型转换:GIF>JPG、GIF>PNG、PNG>JPG、PNG>GIF(X)、BMP>PNG
      参数:
      src - 源图像地址
      format - 包含格式非正式名称的 String:如JPG、JPEG、GIF等
      dest - 目标图像地址
    • gray

      public static final void gray(File src, File tar)
      彩色转为黑白
      参数:
      src - 源图像地址
      tar - 目标图像地址
    • base64Img

      public static String base64Img(File img)
      根据图片转换为base64编码字符串
      参数:
      img - img
      返回:
      String
    • base64

      public static String base64(File img)
    • base64Img

      public static String base64Img(URL url)
    • base64

      public static String base64(URL url)
    • base64Img

      public static boolean base64Img(File file, String str)
      base64 图片转文件
      参数:
      file - file
      str - str
      返回:
      boolean
    • base64

      public static boolean base64(File file, String str)
    • size

      public static int[] size(File img)
      获取文件宽高
      参数:
      img - img
      返回:
      int
    • width

      public static int width(File img)
    • height

      public static int height(File img)