提交 c3a45dfc authored 作者: zhoushaopan's avatar zhoushaopan

[二维码]修改

上级 0b7a008d
......@@ -7,7 +7,9 @@ import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import javassist.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
import sun.misc.BASE64Encoder;
......@@ -27,6 +29,8 @@ import java.util.UUID;
* Author:zsp
*/
public class ZXingUtil {
/** 二维码上传位置 */
private static String codePath = "src/";
/** 二维码宽度 */
......@@ -77,7 +81,7 @@ public class ZXingUtil {
encodeHints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(String.valueOf(taskId),
BarcodeFormat.QR_CODE, width, height, encodeHints);
String filepath = codePath + UUID.randomUUID() + ".png";
String filepath = ResourceUtils.getURL("classpath:").getPath() + UUID.randomUUID() + ".png";
Path path = FileSystems.getDefault().getPath(filepath);
MatrixToImageWriter.writeToPath(bitMatrix,"png",path);
return ImageToBase64ByLocal(filepath);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论