Browse Source

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

release_toaliyun_real
Stormeye.Wu 7 years ago
parent
commit
6f2d669cc5
2 changed files with 41 additions and 18 deletions
  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 View File

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


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


File dest = new File(destPath); File dest = new File(destPath);
@@ -176,21 +177,35 @@ public class WxAppinfoServiceImpl implements WxAppinfoService {
Date imgDate = new Date(); Date imgDate = new Date();
if(type == 0) { if(type == 0) {
final File codeFile = wxMaService.getQrcodeService().createQrcode(pathStr, QRCodeUtils.QR_WIDTH); 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); org.apache.commons.io.FileUtils.forceDelete(codeFile);
} else { } else {
final File codeFile = wxMaService.getQrcodeService().createWxaCodeUnlimit(sceneParam, pageUrl, QRCodeUtils.QR_WIDTH, autoColor, color, isHyaline); 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); org.apache.commons.io.FileUtils.forceDelete(codeFile);
} }




+ 16
- 8
mallinkService/src/main/java/com/iformall/utils/QRCodeUtils.java View File

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


public static final int QR_WIDTH = 430; public static final int QR_WIDTH = 430;
public static final int QR_HIGHT = 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_TIP = 90;
public static final int QR_H_TIP2 = 120; public static final int QR_H_TIP2 = 120;


/** /**
* 二维码 + 文字1 * 二维码 + 文字1
*
* @param oldimg * @param oldimg
* @param newimg * @param newimg
* @param pressText * @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 H_tip = QR_H_TIP; // 文字的高度
int imageWidth = QR_WIDTH; // 图片的宽度 int imageWidth = QR_WIDTH; // 图片的宽度
int imageHeight = QR_HIGHT + QR_H_TIP; // 图片的高度 int imageHeight = QR_HIGHT + QR_H_TIP; // 图片的高度
@@ -60,7 +61,7 @@ public class QRCodeUtils {
FontRenderContext context = tip.getFontRenderContext(); FontRenderContext context = tip.getFontRenderContext();
Rectangle2D bounds = tipFont.getStringBounds(pressText, context); Rectangle2D bounds = tipFont.getStringBounds(pressText, context);
double x = (QR_WIDTH - bounds.getWidth()) / 2; 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); tip.drawLine(0, QR_HIGHT, QR_WIDTH, QR_HIGHT);
@@ -71,7 +72,7 @@ public class QRCodeUtils {
//encoder.encode(image); //encoder.encode(image);
//out.close(); //out.close();


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


/** /**
* 二维码 + 文字1 + 文字2 * 二维码 + 文字1 + 文字2
*
* @param oldimg * @param oldimg
* @param newimg * @param newimg
* @param pressText1 * @param pressText1
* @param pressText2 * @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 H_tip = QR_H_TIP2; // 文字的高度
int imageWidth = QR_WIDTH; // 图片的宽度 int imageWidth = QR_WIDTH; // 图片的宽度
int imageHeight = QR_HIGHT + QR_H_TIP2; // 图片的高度 int imageHeight = QR_HIGHT + QR_H_TIP2; // 图片的高度
@@ -119,21 +121,27 @@ public class QRCodeUtils {
FontRenderContext context = tip.getFontRenderContext(); FontRenderContext context = tip.getFontRenderContext();
Rectangle2D bounds1 = tipFont.getStringBounds(pressText1, context); Rectangle2D bounds1 = tipFont.getStringBounds(pressText1, context);
double x = (QR_WIDTH - bounds1.getWidth()) / 2; 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); Rectangle2D bounds2 = tipFont.getStringBounds(pressText2, context);
x = (QR_WIDTH - bounds2.getWidth()) / 2; 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); //FileOutputStream out = new FileOutputStream(newimg);
ImageIO.write(image, "png", newimg); ImageIO.write(image, "png", newimg);
//JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); //JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
//encoder.encode(image); //encoder.encode(image);
//out.close(); //out.close();


}catch (Exception e) {
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
System.out.println(e); 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…
Cancel
Save