Преглед изворни кода

[二维码支持][修改]:停车二维码

release_toaliyun_real
Stormeye.Wu пре 7 година
родитељ
комит
6f2d669cc5
2 измењених фајлова са 41 додато и 18 уклоњено
  1. +25
    -10
      mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java
  2. +16
    -8
      mallinkService/src/main/java/com/iformall/utils/QRCodeUtils.java

+ 25
- 10
mallinkService/src/main/java/com/iformall/service/impl/WxAppinfoServiceImpl.java Прегледај датотеку

@@ -165,6 +165,7 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {

String filepath = Constant.fileDirectory;
String fileName = sceneParam + ".png";
String destPath1 = filepath + "1_" + fileName;
String destPath = filepath + fileName;

File dest = new File(destPath);
@@ -176,21 +177,35 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
Date imgDate = new Date();
if(type == 0) {
final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH);
if (type == 1) {
QRCodeUtils.graphicsGeneration(codeFile, dest, text1);
} else if (type == 2) {
QRCodeUtils.graphicsGeneration2(codeFile, dest, text1, text2);
if (withText == 1) {
File dest1 = new File(destPath1);
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1);
QRCodeUtils.graphicsGeneration(dest1, dest, text1);
org.apache.commons.io.FileUtils.forceDelete(dest1);
} else if (withText == 2) {
File dest1 = new File(destPath1);
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1);
QRCodeUtils.graphicsGeneration2(dest1, dest, text1, text2);
org.apache.commons.io.FileUtils.forceDelete(dest1);
} else {
org.apache.commons.io.FileUtils.copyFile(codeFile, dest);
}
org.apache.commons.io.FileUtils.copyFile(codeFile, dest);
org.apache.commons.io.FileUtils.forceDelete(codeFile);
} else {
final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline);
if (type == 1) {
QRCodeUtils.graphicsGeneration(codeFile, dest, text1);
} else if (type == 2) {
QRCodeUtils.graphicsGeneration2(codeFile, dest, text1, text2);
if (withText == 1) {
File dest1 = new File(destPath1);
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1);
QRCodeUtils.graphicsGeneration(dest1, dest, text1);
org.apache.commons.io.FileUtils.forceDelete(dest1);
} else if (withText == 2) {
File dest1 = new File(destPath1);
org.apache.commons.io.FileUtils.copyFile(codeFile, dest1);
QRCodeUtils.graphicsGeneration2(dest1, dest, text1, text2);
org.apache.commons.io.FileUtils.forceDelete(dest1);
} else {
org.apache.commons.io.FileUtils.copyFile(codeFile, dest);
}
org.apache.commons.io.FileUtils.copyFile(codeFile, dest);
org.apache.commons.io.FileUtils.forceDelete(codeFile);
}



+ 16
- 8
mallinkService/src/main/java/com/iformall/utils/QRCodeUtils.java Прегледај датотеку

@@ -16,17 +16,18 @@ public class QRCodeUtils {

public static final int QR_WIDTH = 430;
public static final int QR_HIGHT = 430;
public static final int QR_FONT_SIZE = 19;
public static final int QR_FONT_SIZE = 19;
public static final int QR_H_TIP = 90;
public static final int QR_H_TIP2 = 120;

/**
* 二维码 + 文字1
*
* @param oldimg
* @param newimg
* @param pressText
*/
public static void graphicsGeneration(File oldimg,File newimg,String pressText) {
public static void graphicsGeneration(File oldimg, File newimg, String pressText) {
int H_tip = QR_H_TIP; // 文字的高度
int imageWidth = QR_WIDTH; // 图片的宽度
int imageHeight = QR_HIGHT + QR_H_TIP; // 图片的高度
@@ -60,7 +61,7 @@ public class QRCodeUtils {
FontRenderContext context = tip.getFontRenderContext();
Rectangle2D bounds = tipFont.getStringBounds(pressText, context);
double x = (QR_WIDTH - bounds.getWidth()) / 2;
tip.drawString(pressText, (int)x, QR_HIGHT + 50);
tip.drawString(pressText, (int) x, QR_HIGHT + 50);

// 分割线
tip.drawLine(0, QR_HIGHT, QR_WIDTH, QR_HIGHT);
@@ -71,7 +72,7 @@ public class QRCodeUtils {
//encoder.encode(image);
//out.close();

}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
@@ -80,12 +81,13 @@ public class QRCodeUtils {

/**
* 二维码 + 文字1 + 文字2
*
* @param oldimg
* @param newimg
* @param pressText1
* @param pressText2
*/
public static void graphicsGeneration2(File oldimg,File newimg,String pressText1, String pressText2) {
public static void graphicsGeneration2(File oldimg, File newimg, String pressText1, String pressText2) {
int H_tip = QR_H_TIP2; // 文字的高度
int imageWidth = QR_WIDTH; // 图片的宽度
int imageHeight = QR_HIGHT + QR_H_TIP2; // 图片的高度
@@ -119,21 +121,27 @@ public class QRCodeUtils {
FontRenderContext context = tip.getFontRenderContext();
Rectangle2D bounds1 = tipFont.getStringBounds(pressText1, context);
double x = (QR_WIDTH - bounds1.getWidth()) / 2;
tip.drawString(pressText1, (int)x, QR_HIGHT + 50);
tip.drawString(pressText1, (int) x, QR_HIGHT + 50);

Rectangle2D bounds2 = tipFont.getStringBounds(pressText2, context);
x = (QR_WIDTH - bounds2.getWidth()) / 2;
tip.drawString(pressText2, (int)x, QR_HIGHT + 90);
tip.drawString(pressText2, (int) x, QR_HIGHT + 90);
//FileOutputStream out = new FileOutputStream(newimg);
ImageIO.write(image, "png", newimg);
//JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//encoder.encode(image);
//out.close();

}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}

}

public static void main(String[] args) {
File souce = new File("./uploads/null.png");
File dest = new File("./uploads/new.png");
graphicsGeneration(souce, dest, "长融世贸广场停车专用");
}
}

Loading…
Откажи
Сачувај