Class MGL_ImageUtils

java.lang.Object
tech.mgl.core.utils.img.MGL_ImageUtils

public class MGL_ImageUtils extends Object
ClassName: ImageUtils
Author:
hotpot https://mgl.tech
  • Constructor Details

    • MGL_ImageUtils

      public MGL_ImageUtils()
  • Method Details

    • cropImage

      public static boolean cropImage(String src, String dest, int x, int y, int w, int h) throws IOException
      图片裁剪
      Parameters:
      src - 原图
      dest - 目标图
      x - 起始X
      y - 起始Y
      w - 剪切宽度
      h - 剪切高度
      Returns:
      boolean 返回类型
      Throws:
      IOException - 参数
    • rotateImage

      public static BufferedImage rotateImage(String srcPath, String destPath, int angel) throws IOException
      旋转图片,如果PNG图片旋转后背景是透明背景
      Parameters:
      srcPath - 原
      destPath - 目
      angel - 角度
      Returns:
      BufferedImage 返回类型
      Throws:
      IOException - 参数
    • rotateImage

      public static BufferedImage rotateImage(String srcPath, String destPath, int angel, boolean setTran) throws IOException
      旋转图片,如果输入的是是JPG图片,当输出格式PNG并setTran=true时输出背景为透明
      Parameters:
      srcPath -
      destPath -
      angel -
      setTran -
      Returns:
      Throws:
      IOException - 参数
    • getTransparentImg

      public static BufferedImage getTransparentImg(int width, int height)
      获取一张透明图
      Parameters:
      width -
      height -
      Returns:
      参数
    • append

      public static boolean append(List<MGL_ImgVo> inputFileNameList, String outputFileName, int outputW, int outputH) throws Exception
      合并图片
      Parameters:
      inputFileNameList -
      outputFileName -
      outputW -
      outputH -
      Returns:
      Throws:
      Exception - 参数
    • main

      public static void main(String[] args)
    • isImage

      public static boolean isImage(String fileName)
    • isImage

      public static boolean isImage(String fileName, List<String> ext)
    • isImage

      public static boolean isImage(Object obj) throws Exception
      Throws:
      Exception
    • fetchNetImg

      public static byte[] fetchNetImg(String url) throws IOException
      从网络获取图片字节数组
      Parameters:
      url - 图片的网络地址
      Returns:
      图片的字节数组,如果获取失败则抛出异常
      Throws:
      IOException - 如果网络请求失败或响应状态异常
    • downloadImage

      public static void downloadImage(String imageUrl, String savePath)
      下载网络图片到本地
      Parameters:
      imageUrl - 网络图片URL
      savePath - 本地保存路径(包含文件名)
      Throws:
      IOException - 如果下载失败则抛出异常
      InterruptedException - 如果请求被中断