|
@@ -11,19 +11,16 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-/*import com.sun.image.codec.jpeg.JPEGCodec;
|
|
|
-import com.sun.image.codec.jpeg.JPEGImageDecoder;*/
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.nio.channels.FileChannel;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -78,20 +75,20 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
|
|
|
String replaceUrl = url.replace(replaceOldValue, replaceValue);
|
|
|
log.info("图片replaceUrl:{}", url);
|
|
|
String localUrl = LoadFileUtil.downLoadFromUrl(replaceUrl, downloadUrl);
|
|
|
- File file = new File(localUrl);
|
|
|
- /* JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new FileInputStream(file));
|
|
|
- BufferedImage sourceImg = decoder.decodeAsBufferedImage();
|
|
|
- Integer height = sourceImg.getHeight();
|
|
|
+ File picture = new File(localUrl);
|
|
|
+ BufferedImage sourceImg = null;
|
|
|
+ try {
|
|
|
+ sourceImg = ImageIO.read(new FileInputStream(picture));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String size = String.format("%.1f", picture.length() / 1024.0);
|
|
|
Integer width = sourceImg.getWidth();
|
|
|
- FileInputStream fis = new FileInputStream(file);
|
|
|
- FileChannel fc = fis.getChannel();
|
|
|
- BigDecimal fileSize = new BigDecimal(fc.size());
|
|
|
- String size = String.valueOf(fileSize.divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP));
|
|
|
+ Integer height = sourceImg.getHeight();
|
|
|
materialImageInfo.setSize(size);
|
|
|
+ materialImageInfo.setHeight(String.valueOf(height));
|
|
|
materialImageInfo.setWidth(String.valueOf(width));
|
|
|
- materialImageInfo.setHeight(String.valueOf(height));*/
|
|
|
materialImageInfoMapper.insertSelective(materialImageInfo);
|
|
|
- // fis.close();
|
|
|
LoadFileUtil.delFile(localUrl);
|
|
|
}
|
|
|
|
|
@@ -131,5 +128,19 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
|
|
|
return materialImageInfoMapper.getCodeList();
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ File picture = new File("D:\\file\\FDXS0435JCY t5.jpg");
|
|
|
+ BufferedImage sourceImg = null;
|
|
|
+ try {
|
|
|
+ sourceImg = ImageIO.read(new FileInputStream(picture));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(String.format("%.1f", picture.length() / 1024.0));// 源图大小
|
|
|
+ System.out.println("宽" + sourceImg.getWidth()); // 源图宽度
|
|
|
+ System.out.println("高" + sourceImg.getHeight()); // 源图高度
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|