This commit is contained in:
admin
2022-09-22 11:27:26 +08:00
parent 6938fbafc0
commit 7dd6ec5f22

View File

@@ -1,7 +1,10 @@
package sc545.pay.utils; package sc545.pay.utils;
import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -16,6 +19,7 @@ import java.util.Random;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@@ -1172,6 +1176,31 @@ public class Utils {
return pics; return pics;
} }
/**
* 获取图片的宽高
* @param url
* @return
*/
public static int[] getImgWH(String url){
int srcWidth = 0; // 源图宽度
int srcHeight = 0; // 源图高度
try{
URL url1 = new URL(url);
URLConnection connection = url1.openConnection();
connection.setDoOutput(true);
BufferedImage image = ImageIO.read(connection.getInputStream());
if(image==null) return new int[]{0,0};
srcWidth = image .getWidth(); // 源图宽度
srcHeight = image .getHeight(); // 源图高度
}catch(Exception e){e.printStackTrace();}
return new int[]{srcWidth,srcHeight};
}
public static Map<String, Object> urlParamToMaps(String q) { public static Map<String, Object> urlParamToMaps(String q) {
if(q==null||"".equals(q.trim())) return null; if(q==null||"".equals(q.trim())) return null;