diff --git a/04.系统编码/Backend/pom.xml b/04.系统编码/Backend/pom.xml
index 22bce2b..992203d 100644
--- a/04.系统编码/Backend/pom.xml
+++ b/04.系统编码/Backend/pom.xml
@@ -51,6 +51,7 @@
1.0.29
+
diff --git a/04.系统编码/Backend/src/main/java/com/userinformation/backend/config/WebMvcConfig.java b/04.系统编码/Backend/src/main/java/com/userinformation/backend/config/WebMvcConfig.java
index edc3787..2debb5a 100644
--- a/04.系统编码/Backend/src/main/java/com/userinformation/backend/config/WebMvcConfig.java
+++ b/04.系统编码/Backend/src/main/java/com/userinformation/backend/config/WebMvcConfig.java
@@ -1,5 +1,6 @@
package com.userinformation.backend.config;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@@ -12,8 +13,12 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
+
+ @Value("${custom.image.path}")
+ private String path;
+
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/product/**").addResourceLocations("file:D:\\Deployments\\LamanRadar\\product\\");
+ registry.addResourceHandler("/product/**").addResourceLocations("file:" + path + "/");
}
}
diff --git a/04.系统编码/Backend/src/main/java/com/userinformation/backend/controller/ImageController.java b/04.系统编码/Backend/src/main/java/com/userinformation/backend/controller/ImageController.java
new file mode 100644
index 0000000..18bd322
--- /dev/null
+++ b/04.系统编码/Backend/src/main/java/com/userinformation/backend/controller/ImageController.java
@@ -0,0 +1,29 @@
+package com.userinformation.backend.controller;
+
+import java.io.IOException;
+
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.userinformation.backend.service.ImageService;
+import com.userinformation.backend.util.RequestResult;
+
+/**
+ * @describe: 图片处理控制层
+ * @author: xiaowuler
+ * @createTime: 2021-12-03 13:10
+ */
+@RestController
+@RequestMapping("image")
+public class ImageController {
+
+ private final ImageService imageService;
+ public ImageController(ImageService imageService){
+ this.imageService = imageService;
+ }
+
+ @PostMapping("convert")
+ public RequestResult convert(String url) throws IOException {
+ return RequestResult.success(imageService.convert(url));
+ }
+}
diff --git a/04.系统编码/Backend/src/main/java/com/userinformation/backend/service/ImageService.java b/04.系统编码/Backend/src/main/java/com/userinformation/backend/service/ImageService.java
new file mode 100644
index 0000000..3b979fa
--- /dev/null
+++ b/04.系统编码/Backend/src/main/java/com/userinformation/backend/service/ImageService.java
@@ -0,0 +1,43 @@
+package com.userinformation.backend.service;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.Locale;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
+
+/**
+ * @describe: 图片处理 逻辑层
+ * @author: xiaowuler
+ * @createTime: 2021-12-03 13:12
+ */
+@Service
+public class ImageService {
+
+ @Value("${custom.image.path}")
+ private String imagePath;
+
+ @Value("${custom.image.url}")
+ private String imageUrl;
+
+ private final static String TIF_FILE_SUFFIX = ".tif";
+ private final static String PNG_FILE_SUFFIX = ".png";
+
+ public String convert(String url) throws IOException {
+ String filepath = url.replace(imageUrl, imagePath);
+ File sourceFile = new File(filepath);
+ Assert.isTrue(sourceFile.exists(), "文件不存在");
+ Assert.isTrue(filepath.toLowerCase(Locale.ROOT).endsWith(TIF_FILE_SUFFIX), "文件格式不正确");
+ String targetFilePath = filepath.replace(TIF_FILE_SUFFIX, PNG_FILE_SUFFIX);
+ File targetFile = new File(targetFilePath);
+ if (!targetFile.exists()){
+ BufferedImage image = ImageIO.read(sourceFile);
+ ImageIO.write(image, "png", targetFile);
+ }
+ return targetFilePath.replace(imagePath, imageUrl);
+ }
+}
diff --git a/04.系统编码/Backend/src/main/resources/application.yml b/04.系统编码/Backend/src/main/resources/application.yml
index 246ed6f..69c8ccb 100644
--- a/04.系统编码/Backend/src/main/resources/application.yml
+++ b/04.系统编码/Backend/src/main/resources/application.yml
@@ -6,3 +6,7 @@ spring:
username: root
password: 3cqscbr@only1
driver-class-name: com.mysql.cj.jdbc.Driver
+custom:
+ image:
+ url: http://112.124.40.88:8002/product
+ path: D:/Deployments/LamanRadar/product
diff --git a/04.系统编码/Backend/src/test/java/com/userinformation/backend/UserInformationApplicationTests.java b/04.系统编码/Backend/src/test/java/com/userinformation/backend/UserInformationApplicationTests.java
index e184ec9..6d25383 100644
--- a/04.系统编码/Backend/src/test/java/com/userinformation/backend/UserInformationApplicationTests.java
+++ b/04.系统编码/Backend/src/test/java/com/userinformation/backend/UserInformationApplicationTests.java
@@ -1,5 +1,11 @@
package com.userinformation.backend;
+import javax.imageio.ImageIO;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@@ -7,7 +13,11 @@ import org.springframework.boot.test.context.SpringBootTest;
class UserInformationApplicationTests {
@Test
- void contextLoads() {
+ void contextLoads() throws IOException {
+ File inputFile = new File("C:\\Users\\xiaowuler\\Desktop\\images\\decision-support\\plan-advice\\control-experiment\\TFLD_Q2.tif");
+ File outputFile = new File("C:\\Users\\xiaowuler\\Desktop\\output.png");
+ BufferedImage image = ImageIO.read(inputFile);
+ ImageIO.write(image, "png", outputFile);
}
}
diff --git a/04.系统编码/Frontend/src/components/DecisionSupport.vue b/04.系统编码/Frontend/src/components/DecisionSupport.vue
index ab19541..6c85fae 100644
--- a/04.系统编码/Frontend/src/components/DecisionSupport.vue
+++ b/04.系统编码/Frontend/src/components/DecisionSupport.vue
@@ -63,6 +63,7 @@
import { onMounted, reactive, toRefs } from 'vue';
import * as Tiff from 'browser-tiff.js';
import { DecisionSupportConfig } from '../uilts/Config';
+import { get } from '../uilts/axios';
export default {
name: 'DecisionSupport',
@@ -128,18 +129,28 @@
}
const initImage = (type, imgName, index) => {
- var xhr = new XMLHttpRequest();
- xhr.responseType = 'arraybuffer';
- xhr.open('GET', DecisionSupportConfig.getUrl(type, imgName));
- xhr.onload = function (e) {
- let tiff = new Tiff({buffer: xhr.response});
+ console.log(DecisionSupportConfig.getUrl(type, imgName))
+ get(DecisionSupportConfig.getUrl(type, imgName)).then((response: any) => {
+ console.log(response)
+ let tiff = new Tiff({buffer: response.data});
let canvas = tiff.toCanvas();
let image = new Image();
image.src = canvas.toDataURL("image/png");
options.items[index].imgUrl = image.src;
options.items[index].preview = [image.src];
- };
- xhr.send();
+ })
+ // var xhr = new XMLHttpRequest();
+ // xhr.responseType = 'arraybuffer';
+ // xhr.open('GET', DecisionSupportConfig.getUrl(type, imgName));
+ // xhr.onload = function (e) {
+ // let tiff = new Tiff({buffer: xhr.response});
+ // let canvas = tiff.toCanvas();
+ // let image = new Image();
+ // image.src = canvas.toDataURL("image/png");
+ // options.items[index].imgUrl = image.src;
+ // options.items[index].preview = [image.src];
+ // };
+ // xhr.send();
}
return {
diff --git a/04.系统编码/Frontend/src/uilts/axios.ts b/04.系统编码/Frontend/src/uilts/axios.ts
index 7db59eb..d18d47e 100644
--- a/04.系统编码/Frontend/src/uilts/axios.ts
+++ b/04.系统编码/Frontend/src/uilts/axios.ts
@@ -5,8 +5,8 @@ import { ElLoading } from 'element-plus'
let loading = null;
const service = axios.create({
- // baseURL:"http://localhost:8002",
- baseURL:"",
+ baseURL:"http://localhost:8002",
+ // baseURL:"",
timeout: 500000
})