|
@@ -1,6 +1,7 @@
|
|
package com.fdkankan.common.util;
|
|
package com.fdkankan.common.util;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import java.io.InputStream;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
@@ -10,6 +11,9 @@ import java.awt.geom.RoundRectangle2D;
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
|
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
|
+import org.springframework.core.io.support.ResourcePatternResolver;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
public class LogoConfig {
|
|
public class LogoConfig {
|
|
@@ -28,22 +32,26 @@ public class LogoConfig {
|
|
|
|
|
|
int matrixWidth = matrixImage.getWidth();
|
|
int matrixWidth = matrixImage.getWidth();
|
|
int matrixHeigh = matrixImage.getHeight();
|
|
int matrixHeigh = matrixImage.getHeight();
|
|
- /**
|
|
|
|
- * 读取Logo图片
|
|
|
|
- */
|
|
|
|
- ClassPathResource classPathResource = null;
|
|
|
|
- if(logoPath == null){
|
|
|
|
-// logoPath = this.getClass().getResource("/static/img/logo.png").getPath();
|
|
|
|
- classPathResource = new ClassPathResource("static/img/logo.jpg");
|
|
|
|
-// logoPath =classPathResource.getURL().getPath();
|
|
|
|
- }
|
|
|
|
|
|
+ File file = null;
|
|
BufferedImage logo = null;
|
|
BufferedImage logo = null;
|
|
try {
|
|
try {
|
|
- if(StrUtil.isNotEmpty(logoPath)){
|
|
|
|
- logo = ImageIO.read(new File(logoPath));
|
|
|
|
- }else{
|
|
|
|
- logo = ImageIO.read(classPathResource.getFile());
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 读取Logo图片
|
|
|
|
+ */
|
|
|
|
+ if(StrUtil.isEmpty(logoPath)){
|
|
|
|
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
|
|
|
+ Resource[] resources = resolver.getResources("static/img/logo.jpg");
|
|
|
|
+ Resource resource = resources[0];
|
|
|
|
+ //获得文件流,因为在jar文件中,不能直接通过文件资源路径拿到文件,但是可以在jar包中拿到文件流
|
|
|
|
+ InputStream inputStream = resource.getInputStream();
|
|
|
|
+ logo = ImageIO.read(inputStream);
|
|
|
|
+ }else {
|
|
|
|
+ file = new File(logoPath);
|
|
|
|
+ logo = ImageIO.read(file);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}catch (IOException e){
|
|
}catch (IOException e){
|
|
log.info("读取图片流失败,path="+ logoPath, e);
|
|
log.info("读取图片流失败,path="+ logoPath, e);
|
|
}
|
|
}
|