xiaoyong931011
2021-03-15 39ae83445d16d37a3c02e0dfdeb1be15eac0e2c2
zq-erp/src/main/java/com/matrix/component/tools/ImageUtil.java
@@ -2,8 +2,10 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@@ -91,4 +93,44 @@
      System.out.println("系统字体数:" + fontCount);
   }
   public static void downloadPicture(String imgUrl,String savePath) {
      URL url = null;
      int imageNumber = 0;
      try {
         InputStream inputStream = null;
         HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(imgUrl).openConnection();
         httpURLConnection.setRequestMethod("GET");
         httpURLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36");
         httpURLConnection.setRequestProperty("Accept-Encoding", "gzip");
         httpURLConnection.setRequestProperty("Referer","no-referrer");
         httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
         httpURLConnection.setConnectTimeout(15000);
         httpURLConnection.setReadTimeout(20000);
         inputStream = httpURLConnection.getInputStream();
         FileOutputStream fileOutputStream = new FileOutputStream(new File(savePath));
         ByteArrayOutputStream output = new ByteArrayOutputStream();
         byte[] buffer = new byte[1024];
         int length;
         while ((length = inputStream.read(buffer)) > 0) {
            output.write(buffer, 0, length);
         }
         byte[] context=output.toByteArray();
         fileOutputStream.write(output.toByteArray());
         inputStream.close();
         fileOutputStream.close();
      } catch (MalformedURLException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}