日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

之前有寫過類似的,實現方式大致上都是一樣的

package com.bus.wx.action.code;
 
import JAVA.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
 
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
 
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMApping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
 
import com.bus.plugin.wx.action.WxAction;
import com.bus.wx.util.Limits;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.lys.sys.log.Log;
 
/**
 * 條形碼、二維碼
 * @author hwj
 *
 */
@Scope(value = "prototype")
@Controller("Bar_Qr_Code_Action")
@RequestMapping(value="plug/wx/wwz/{bcflag}/barqrcode")
public class Bar_Qr_Code_Action extends WxAction{
 
	private static final int LogoPart = 4;
	private static final int BLACK = 0xFF000000;//用于設置圖案的顏色 
 private static final int WHITE = 0xFFFFFFFF; //用于背景色 
 String format = "png";
 
 
 
public static BufferedImage toBufferedImage(BitMatrix matrix) { 
 int width = matrix.getWidth(); 
 int height = matrix.getHeight(); 
 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
 for (int x = 0; x < width; x++) { 
 for (int y = 0; y < height; y++) { 
 image.setRGB(x, y, (matrix.get(x, y) ? BLACK : WHITE)); 
// image.setRGB(x, y, (matrix.get(x, y) ? Color.YELLOW.getRGB() : Color.CYAN.getRGB())); 
 } 
 } 
 return image; 
}
 
	 public BufferedImage LogoMatrix(BufferedImage matrixImage) throws IOException{ 
	 /** 
	 * 讀取二維碼圖片,并構建繪圖對象 
	 */ 
	 Graphics2D g2 = matrixImage.createGraphics(); 
	 
	 int matrixWidth = matrixImage.getWidth(); 
	 int matrixHeigh = matrixImage.getHeight(); 
	 
	 /** 
	 * 讀取Logo圖片 
	 */ 
	 String path=request.getSession().getServletContext().getRealPath("/images/logo/dzjkklog.png");
	 BufferedImage logo = ImageIO.read(new File(path)); 
	 
	 //開始繪制圖片 
	 g2.drawImage(logo,matrixWidth/5*2,matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5, null);//繪制 
	 BasicStroke stroke = new BasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND); 
	 g2.setStroke(stroke);// 設置筆畫對象 
	 //指定弧度的圓角矩形 
	 RoundRectangle2D.Float round = new RoundRectangle2D.Float(matrixWidth/5*2, matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5,20,20); 
	 g2.setColor(Color.white); 
	 g2.draw(round);// 繪制圓弧矩形 
	 
	 //設置logo 有一道灰色邊框 
	 BasicStroke stroke2 = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND); 
	 g2.setStroke(stroke2);// 設置筆畫對象 
	 RoundRectangle2D.Float round2 = new RoundRectangle2D.Float(matrixWidth/5*2+2, matrixHeigh/5*2+2, matrixWidth/5-4, matrixHeigh/5-4,20,20); 
	 g2.setColor(new Color(128,128,128)); 
	 g2.draw(round2);// 繪制圓弧矩形 
	 
	 g2.dispose(); 
	 matrixImage.flush() ; 
	 return matrixImage ; 
	 } 
	 
	
	/**
	 * 生成二維碼:直接將生成的二維碼傳輸到前臺頁面
	 * @param bcflag
	 */
	@RequestMapping(value="createQrCodes",method = RequestMethod.GET)
	public void createQrCodes(@PathVariable String bcflag,String dastid){
		
		String url="掃二維碼出現的內容";
		if(url!=null&&!"".equals(url)){
			ServletOutputStream stream=null;
			try {
				int width=430;
				int height=430;
				stream=response.getOutputStream();
				QRCodeWriter writer=new QRCodeWriter();
				 Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); 
			 
			 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); 
			 hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
			 hints.put(EncodeHintType.MARGIN, 1);//設置二維碼邊的空度,非負數 
			 BitMatrix bitMatrix = new MultiFormatWriter().encode(url,//要編碼的內容 
			 BarcodeFormat.QR_CODE, 
			 width, //條形碼的寬度 
			 height, //條形碼的高度 
			 hints);
				//BitMatrix m=writer.encode(url, BarcodeFormat.QR_CODE, height,width);
				 BufferedImage image = toBufferedImage(bitMatrix); 
			 image = LogoMatrix(image); 
			 if (!ImageIO.write(image, format, stream)) { 
			 throw new IOException("Could not write an image of format " + format); 
			 } 
				} catch (Exception e) {
					Log.in.info(e.getMessage());
				}finally{
					if(stream!=null){
						try {
							stream.flush();
							stream.close();
							} catch (IOException e) {
								Log.in.info(e.getMessage());
							}
					}
				}
		 }
	}
}

 

原文:https://blog.csdn.net/qq_34707456/article/details/103462624

分享到:
標簽:java
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定