|
@@ -11,12 +11,14 @@ 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 it.sauronsoftware.jave.Encoder;
|
|
|
+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 java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.math.BigDecimal;
|
|
@@ -77,18 +79,19 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
|
|
|
log.info("图片replaceUrl:{}", url);
|
|
|
String localUrl = LoadFileUtil.downLoadFromUrl(replaceUrl, downloadUrl);
|
|
|
File file = new File(localUrl);
|
|
|
- it.sauronsoftware.jave.Encoder encoder = new Encoder();
|
|
|
- it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(file);
|
|
|
- String width = String.valueOf((m.getVideo().getSize().getWidth()));
|
|
|
- String height = String.valueOf(m.getVideo().getSize().getHeight());
|
|
|
+ JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new FileInputStream(file));
|
|
|
+ BufferedImage sourceImg = decoder.decodeAsBufferedImage();
|
|
|
+ Integer height = sourceImg.getHeight();
|
|
|
+ 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));
|
|
|
materialImageInfo.setSize(size);
|
|
|
- materialImageInfo.setWidth(width);
|
|
|
- materialImageInfo.setHeight(height);
|
|
|
+ materialImageInfo.setWidth(String.valueOf(width));
|
|
|
+ materialImageInfo.setHeight(String.valueOf(height));
|
|
|
materialImageInfoMapper.insertSelective(materialImageInfo);
|
|
|
+ fis.close();
|
|
|
LoadFileUtil.delFile(localUrl);
|
|
|
}
|
|
|
|
|
@@ -124,45 +127,6 @@ public class MaterialImageInfoServiceImpl extends ServiceImpl<MaterialImageInfoM
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void getImageFile(String url, Long id) {
|
|
|
-
|
|
|
- try {
|
|
|
- if (!Check.isNull(url)) {
|
|
|
- long l = System.currentTimeMillis();
|
|
|
- String replaceUrl = url.replace(replaceOldValue, replaceValue);
|
|
|
- log.info("图片replaceUrl:{}", url);
|
|
|
- String localUrl = LoadFileUtil.downLoadFromUrl(replaceUrl, downloadUrl);
|
|
|
- File file = new File(localUrl);
|
|
|
- it.sauronsoftware.jave.Encoder encoder = new Encoder();
|
|
|
- try {
|
|
|
- it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(file);
|
|
|
- MaterialImageInfo imageInfo = new MaterialImageInfo();
|
|
|
- imageInfo.setId(id);
|
|
|
- String width = String.valueOf((m.getVideo().getSize().getWidth()));
|
|
|
- String height = String.valueOf(m.getVideo().getSize().getHeight());
|
|
|
- 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));
|
|
|
- imageInfo.setSize(size);
|
|
|
- imageInfo.setWidth(width);
|
|
|
- imageInfo.setHeight(height);
|
|
|
- this.updateById(imageInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (
|
|
|
- Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
public List<String> getCodeList() {
|
|
|
return materialImageInfoMapper.getCodeList();
|
|
|
}
|