|
|
|
@@ -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, "长融世贸广场停车专用"); |
|
|
|
} |
|
|
|
} |