|
@@ -6,12 +6,16 @@ import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
|
+import javax.imageio.ImageReadParam;
|
|
|
|
+import javax.imageio.ImageReader;
|
|
|
|
+import javax.imageio.stream.ImageInputStream;
|
|
|
|
+import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
|
|
+import java.awt.geom.AffineTransform;
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileInputStream;
|
|
|
|
|
|
+import java.io.*;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class CreatePOPService {
|
|
public class CreatePOPService {
|
|
@@ -19,7 +23,69 @@ public class CreatePOPService {
|
|
public static final String LOCALQRCODE = Constant.LOCALQRCODE;
|
|
public static final String LOCALQRCODE = Constant.LOCALQRCODE;
|
|
public static final String DEMOQRCODE = Constant.DEMOQRCODE;
|
|
public static final String DEMOQRCODE = Constant.DEMOQRCODE;
|
|
public static final String HTTPOPPQRCODE = Constant.HTTPOPPQRCODE;
|
|
public static final String HTTPOPPQRCODE = Constant.HTTPOPPQRCODE;
|
|
|
|
+ public static final String HTTTESTQRCODE = Constant.HTTTESTQRCODE;
|
|
|
|
+ public static final String TESTQRCODE = Constant.TESTQRCODE;
|
|
|
|
|
|
|
|
+ public String CreateTestShare(String qrcode,String testImg,Integer score,String openid) throws IOException {
|
|
|
|
+ File qrCodeImg = new File(LOCALQRCODE+"/"+qrcode);
|
|
|
|
+ File fileBg = new File(TESTQRCODE+"/"+testImg);
|
|
|
|
+ FileInputStream fis = new FileInputStream(fileBg);
|
|
|
|
+ ImageIcon imageIcon = new ImageIcon(TESTQRCODE+"/"+testImg);
|
|
|
|
+ int iconWidth = imageIcon.getIconWidth();
|
|
|
|
+ int iconHeight = imageIcon.getIconHeight() -200;
|
|
|
|
+
|
|
|
|
+ ImageInputStream iis = ImageIO.createImageInputStream(fileBg);
|
|
|
|
+ Iterator<ImageReader> it = ImageIO.getImageReaders(iis);
|
|
|
|
+ ImageReader r = it.next();
|
|
|
|
+ r.setInput(iis, true);
|
|
|
|
+ ImageReadParam param = r.getDefaultReadParam();
|
|
|
|
+ Rectangle rect = new Rectangle(0, 0, iconWidth, iconHeight);
|
|
|
|
+ param.setSourceRegion(rect);
|
|
|
|
+ BufferedImage bufferedImage = r.read(0, param);
|
|
|
|
+ Graphics2D g = bufferedImage.createGraphics();
|
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
+ g.drawImage(bufferedImage.getScaledInstance(iconWidth, iconHeight, Image.SCALE_SMOOTH), 0, 0, null);
|
|
|
|
+ g.drawImage(ImageIO.read(qrCodeImg), 100, iconHeight-300, 200, 200, null);
|
|
|
|
+
|
|
|
|
+ Graphics2D g2 = (Graphics2D) g;
|
|
|
|
+ int scorex = 0;
|
|
|
|
+ int fenx = 0;
|
|
|
|
+ if(score == 100) {
|
|
|
|
+ scorex = 730;
|
|
|
|
+ fenx = 920;
|
|
|
|
+ } else {
|
|
|
|
+ scorex = 780;
|
|
|
|
+ fenx = 890;
|
|
|
|
+ }
|
|
|
|
+ Font rewardFirstFont = new Font("PingFang SC Bold", Font.BOLD, 130);
|
|
|
|
+ AffineTransform affineTransform = new AffineTransform();
|
|
|
|
+ affineTransform.rotate(Math.toRadians(15), 0, 0);
|
|
|
|
+ Font rotatedFont = rewardFirstFont.deriveFont(affineTransform);
|
|
|
|
+ g2.setColor(Color.decode("#F50000"));
|
|
|
|
+ g2.setFont(rotatedFont);
|
|
|
|
+ g2.drawString(String.valueOf(score),scorex,50);
|
|
|
|
+
|
|
|
|
+ Font rewardLastFont = new Font("PingFang SC Bold", Font.CENTER_BASELINE, 70);
|
|
|
|
+ AffineTransform affineTransform2 = new AffineTransform();
|
|
|
|
+ affineTransform2.rotate(Math.toRadians(15), 0, 0);
|
|
|
|
+ Font rotatedFont2 = rewardLastFont.deriveFont(affineTransform);
|
|
|
|
+ g2.setFont(rotatedFont2);
|
|
|
|
+ g2.setColor(Color.decode("#F50000"));
|
|
|
|
+ g2.drawString("分",fenx,280);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ g.dispose();
|
|
|
|
+ g2.dispose();
|
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
|
+ ImageIO.write(bufferedImage, "jpg", os);
|
|
|
|
+ //保存为图片文件
|
|
|
|
+ FileUtils.writeByteArrayToFile(new File(TESTQRCODE+"/dc/"+openid+".jpg"), os.toByteArray());
|
|
|
|
+ //10、关闭输入输出流
|
|
|
|
+ fis.close();
|
|
|
|
+ os.close();
|
|
|
|
+ return HTTTESTQRCODE+"/"+openid+".jpg";
|
|
|
|
+ }
|
|
|
|
|
|
public String CreatePOP( String wv_phone) throws Exception {
|
|
public String CreatePOP( String wv_phone) throws Exception {
|
|
//宠物图片文件
|
|
//宠物图片文件
|
|
@@ -86,6 +152,7 @@ public class CreatePOPService {
|
|
public static void drawString(Graphics2D g, Color color, Font font, String content, float x, float y) {
|
|
public static void drawString(Graphics2D g, Color color, Font font, String content, float x, float y) {
|
|
g.setColor(color);
|
|
g.setColor(color);
|
|
g.setFont(font);
|
|
g.setFont(font);
|
|
|
|
+// g.rotate(30f);//倾斜?
|
|
g.drawString(content, x, y);
|
|
g.drawString(content, x, y);
|
|
}
|
|
}
|
|
public static void drawString(Graphics2D g, Color color, Font font, String content, float x, float y, int width, int lineWordNum, int linePadding, boolean center) {
|
|
public static void drawString(Graphics2D g, Color color, Font font, String content, float x, float y, int width, int lineWordNum, int linePadding, boolean center) {
|