mirror of
https://gitee.com/open-visual/face-search.git
synced 2025-07-10 19:37:01 +08:00
update:修复由于高版本JDK删除sun.misc.*导致的程序报错的BUG
This commit is contained in:
parent
1352ef80a0
commit
c7c6cc9b7d
@ -9,7 +9,6 @@ import org.opencv.dnn.Dnn;
|
|||||||
import org.opencv.highgui.HighGui;
|
import org.opencv.highgui.HighGui;
|
||||||
import org.opencv.imgcodecs.Imgcodecs;
|
import org.opencv.imgcodecs.Imgcodecs;
|
||||||
import org.opencv.imgproc.Imgproc;
|
import org.opencv.imgproc.Imgproc;
|
||||||
import sun.misc.BASE64Decoder;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -20,6 +19,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图片加载工具
|
* 图片加载工具
|
||||||
@ -66,8 +66,11 @@ public class ImageMat implements Serializable {
|
|||||||
public static ImageMat fromBase64(String base64Str){
|
public static ImageMat fromBase64(String base64Str){
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
BASE64Decoder decoder = new BASE64Decoder();
|
// 新版本JDK被移除,替换为Base64.Decoder
|
||||||
byte[] data = decoder.decodeBuffer(base64Str);
|
// BASE64Decoder decoder = new BASE64Decoder();
|
||||||
|
// byte[] data = decoder.decodeBuffer(base64Str);
|
||||||
|
Base64.Decoder decoder = Base64.getMimeDecoder();
|
||||||
|
byte[] data = decoder.decode(base64Str);
|
||||||
inputStream = new ByteArrayInputStream(data);
|
inputStream = new ByteArrayInputStream(data);
|
||||||
return fromInputStream(inputStream);
|
return fromInputStream(inputStream);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.visual.face.search.core.utils;
|
package com.visual.face.search.core.utils;
|
||||||
|
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import sun.misc.BASE64Encoder;
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class MatUtil {
|
public class MatUtil {
|
||||||
@ -42,8 +42,11 @@ public class MatUtil {
|
|||||||
byteArrayOutputStream = new ByteArrayOutputStream();
|
byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
ImageIO.write(matToBufferedImage(mat), "jpg", byteArrayOutputStream);
|
ImageIO.write(matToBufferedImage(mat), "jpg", byteArrayOutputStream);
|
||||||
byte[] bytes = byteArrayOutputStream.toByteArray();
|
byte[] bytes = byteArrayOutputStream.toByteArray();
|
||||||
BASE64Encoder encoder = new BASE64Encoder();
|
// 新版本JDK被移除,替换为Base64.Encoder
|
||||||
return encoder.encodeBuffer(Objects.requireNonNull(bytes));
|
// BASE64Encoder encoder = new BASE64Encoder();
|
||||||
|
// return encoder.encodeBuffer(Objects.requireNonNull(bytes));
|
||||||
|
Base64.Encoder encoder = Base64.getMimeEncoder();
|
||||||
|
return encoder.encodeToString(Objects.requireNonNull(bytes));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}finally {
|
}finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user