sige 2 years ago
parent
commit
ddca0f4eb4
  1. 29
      src/src/main/java/com/my/graphiteDigesterBg/api/ApiCamera.java
  2. 3
      src/src/main/resources/application-dev.yml
  3. 2
      src/web/src/pages/main/contents/OperationCamera.vue

29
src/src/main/java/com/my/graphiteDigesterBg/api/ApiCamera.java

@ -1,21 +1,42 @@
package com.my.graphiteDigesterBg.api; package com.my.graphiteDigesterBg.api;
import com.my.graphiteDigesterBg.diframe.DiApiControllerBase; import com.my.graphiteDigesterBg.diframe.DiApiControllerBase;
import com.my.graphiteDigesterBg.diframe.DiApiResponse; import com.my.graphiteDigesterBg.diframe.DiApiResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.io.File;
import java.io.FileInputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Base64; import java.util.Base64;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Controller @Controller
public class ApiCamera extends DiApiControllerBase { public class ApiCamera extends DiApiControllerBase {
@Value("${camera.image-path}")
private String imagePath;
@ResponseBody @ResponseBody
@PostMapping("/api/camera/image") @PostMapping("/api/camera/image")
public DiApiResponse getImage() { public DiApiResponse getImage() {
// ByteBuffer buffer = ByteBuffer.allocate(1024);
// byte[] bytes = buffer.array();
// String base64Text = Base64.getEncoder().encodeToString(bytes);
String base64Data = "data:image/image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAUCAYAAACJfM0wAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAH8SURBVDiNtZM/aBNxFMc/791PLJihQ4QMFhJQ7ODgmIJDbxAEXQoJuAqSzOLSQ4c4lFAoOGSQdHEtpOBSQXDo4pChg2NBQQfBDBkyKLRw93sOl1KT3LVC4ne5433f+7w/x0GO2t39Tnu3d5jr7/YO2939Tp4vAK3X75avXosf+sTfOjNUFTx4fGahoqDg/bmvgX45/e3et55tjGTrzd4dleAjQmmi0hNC/B113zLJPq6AK6NMbmUMvCX3nQZBB5uCziOhpBp0HMZ6ZkLAc/yVIVg2QN0LhFKmbay73M7GIyQHmuppXk+AM/AnYnuCJvFFpEvlA4eTt8C9M3BRHLe9BL/m4apSMCjC+cSrhhxcvPnl+rtc50PlK/PjiUjfsBOMVaAEnCD0x2NVgSVggHAsyJKZVacZsxOb9DcbtbWoUQ9Vkw0A7/121KiHUaMeeu+3AVSTjahRDzcbtTVM+jPDtbu9ycsaMUJ//LwB3DQYifE57ctdgWXgK8YPBIdRRSa3nz1FmlBGJAYrpiEKiJTTdyuMM0uIODA3Dc08hcBR1KyvRM1aJTEJ05jsRM1aJWrWKoLsACQmYRqrrwgc/esp9jCLgVVEqhgDsA/jkgfpr2x94BgRh/F4eupZ8IKkAqP/wB2qGd3Fc62rp4PiS7AtYLgA4tDDq9Of11t/AC8CsohkwY6rAAAAAElFTkSuQmCC";
Map<String, String> response = new HashMap<>();
response.put("data", null);
File file = new File(this.imagePath);
if ( !file.exists() ) {
return this.success(response);
}
byte[] bytes = new byte[(int)file.length()];
try {
FileInputStream fis = new FileInputStream(file);
fis.read(bytes);
fis.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
String base64Image = Base64.getEncoder().encodeToString(bytes);
String base64Data = "data:image/image/png;base64," + base64Image;
return this.success(Map.of("data",base64Data)); return this.success(Map.of("data",base64Data));
} }
} }

3
src/src/main/resources/application-dev.yml

@ -8,6 +8,9 @@ spring:
server: server:
port: 8080 port: 8080
camera:
image-path: D:/image.png
#mybatis: #mybatis:
# configuration: # configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

2
src/web/src/pages/main/contents/OperationCamera.vue

@ -1,6 +1,6 @@
<template> <template>
<div class="h-full flex flex-col bg-white rounded-2xl p-5"> <div class="h-full flex flex-col bg-white rounded-2xl p-5">
<div class="camera h-0 grow rounded-2xl flex flex-col justify-center items-center">
<div class="camera h-0 grow rounded-2xl flex flex-col justify-center items-center p-1">
<div v-if="null === imageData"> <div v-if="null === imageData">
<p class="m-0 text-center"><img src="../../../assets/icon/camera-off.svg" /></p> <p class="m-0 text-center"><img src="../../../assets/icon/camera-off.svg" /></p>
<p class="m-0 mt-2 text-2xl text-white">未检测到照相设备</p> <p class="m-0 mt-2 text-2xl text-white">未检测到照相设备</p>

Loading…
Cancel
Save