当前位置: 首页 > news >正文

香港网站icp备案推广赚钱软件排行

香港网站icp备案,推广赚钱软件排行,营销型网站外包,衡水网站联系电话之前朋友问我关于二维码的,当时为了帮他我就去问问了前端的怎么编写的二维码。现在刚好我的项目里也需要设置二维码,刚好用上了。嘻嘻! QRCode.js 是一个用于生成二维码图片的插件。 http://code.ciaoca.com/javascript/qrcode/ 去这里看吧&…

之前朋友问我关于二维码的,当时为了帮他我就去问问了前端的怎么编写的二维码。现在刚好我的项目里也需要设置二维码,刚好用上了。嘻嘻!

QRCode.js 是一个用于生成二维码图片的插件。

http://code.ciaoca.com/javascript/qrcode/  去这里看吧!

我朋友用的是java编写的。很棒的!

  1 package twoDimensionCode;  
  2   
  3 import java.awt.Color;  
  4 import java.awt.Graphics2D;  
  5 import java.awt.image.BufferedImage;  
  6 import java.io.File;  
  7 import java.io.FileOutputStream;
  8 import java.io.IOException;  
  9 import java.io.InputStream;  
 10 import java.io.OutputStream;  
 11   
 12 import javax.imageio.ImageIO;  
 13   
 14 import jp.sourceforge.qrcode.QRCodeDecoder;  
 15 import jp.sourceforge.qrcode.exception.DecodingFailedException;  
 16   
 17 import com.swetake.util.Qrcode;  
 18   
 19 public class TwoDimensionCode {  
 20       
 21     /** 
 22      * 生成二维码(QRCode)图片 
 23      * @param content 存储内容 
 24      * @param imgPath 图片路径 
 25      */  
 26     public void encoderQRCode(String content, String imgPath) {  
 27         this.encoderQRCode(content, imgPath, "png", 7);  
 28     }  
 29       
 30     /** 
 31      * 生成二维码(QRCode)图片 
 32      * @param content 存储内容 
 33      * @param output 输出流 
 34      */  
 35     public void encoderQRCode(String content, OutputStream output) {  
 36         this.encoderQRCode(content, output, "png", 7);  
 37     }  
 38       
 39     /** 
 40      * 生成二维码(QRCode)图片 
 41      * @param content 存储内容 
 42      * @param imgPath 图片路径 
 43      * @param imgType 图片类型 
 44      */  
 45     public void encoderQRCode(String content, String imgPath, String imgType) {  
 46         this.encoderQRCode(content, imgPath, imgType, 7);  
 47     }  
 48       
 49     /** 
 50      * 生成二维码(QRCode)图片 
 51      * @param content 存储内容 
 52      * @param output 输出流 
 53      * @param imgType 图片类型 
 54      */  
 55     public void encoderQRCode(String content, OutputStream output, String imgType) {  
 56         this.encoderQRCode(content, output, imgType, 7);  
 57     }  
 58   
 59     /** 
 60      * 生成二维码(QRCode)图片 
 61      * @param content 存储内容 
 62      * @param imgPath 图片路径 
 63      * @param imgType 图片类型 
 64      * @param size 二维码尺寸 
 65      */  
 66     public void encoderQRCode(String content, String imgPath, String imgType, int size) {  
 67         try {  
 68             BufferedImage bufImg = this.qRCodeCommon(content, imgType, size);  
 69               
 70             File imgFile = new File(imgPath);  
 71             // 生成二维码QRCode图片  
 72             ImageIO.write(bufImg, imgType, imgFile);  
 73         } catch (Exception e) {  
 74             e.printStackTrace();  
 75         }  
 76     }  
 77   
 78     /** 
 79      * 生成二维码(QRCode)图片 
 80      * @param content 存储内容 
 81      * @param output 输出流 
 82      * @param imgType 图片类型 
 83      * @param size 二维码尺寸 
 84      */  
 85     public void encoderQRCode(String content, OutputStream output, String imgType, int size) {  
 86         try {  
 87             BufferedImage bufImg = this.qRCodeCommon(content, imgType, size);  
 88             // 生成二维码QRCode图片  
 89             ImageIO.write(bufImg, imgType, output);  
 90         } catch (Exception e) {  
 91             e.printStackTrace();  
 92         }  
 93     }  
 94       
 95     /** 
 96      * 生成二维码(QRCode)图片的公共方法 
 97      * @param content 存储内容 
 98      * @param imgType 图片类型 
 99      * @param size 二维码尺寸 
100      * @return 
101      */  
102     private BufferedImage qRCodeCommon(String content, String imgType, int size) {  
103         BufferedImage bufImg = null;  
104         try {  
105             Qrcode qrcodeHandler = new Qrcode();    
106             // 设置二维码排错率,可选L(7%)、M(15%)、Q(25%)、H(30%),排错率越高可存储的信息越少,但对二维码清晰度的要求越小  
107             qrcodeHandler.setQrcodeErrorCorrect('M');  
108             qrcodeHandler.setQrcodeEncodeMode('B');  
109             // 设置设置二维码尺寸,取值范围1-40,值越大尺寸越大,可存储的信息越大  
110             qrcodeHandler.setQrcodeVersion(size);  
111             // 获得内容的字节数组,设置编码格式  
112             byte[] contentBytes = content.getBytes("utf-8");  
113             // 图片尺寸  
114             int imgSize = 67 + 12 * (size - 1);  
115             bufImg = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_RGB);  
116             Graphics2D gs = bufImg.createGraphics();  
117             // 设置背景颜色  
118             gs.setBackground(Color.WHITE);  
119             gs.clearRect(0, 0, imgSize, imgSize);  
120   
121             // 设定图像颜色> BLACK  
122             gs.setColor(Color.BLACK);  
123             // 设置偏移量,不设置可能导致解析出错  
124             int pixoff = 2;  
125             // 输出内容> 二维码  
126             if (contentBytes.length > 0 && contentBytes.length < 800) {  
127                 boolean[][] codeOut = qrcodeHandler.calQrcode(contentBytes);  
128                 for (int i = 0; i < codeOut.length; i++) {  
129                     for (int j = 0; j < codeOut.length; j++) {  
130                         if (codeOut[j][i]) {  
131                             gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3);  
132                         }  
133                     }  
134                 }  
135             } else {  
136                 throw new Exception("QRCode content bytes length = " + contentBytes.length + " not in [0, 800].");  
137             }  
138             gs.dispose();  
139             bufImg.flush();  
140         } catch (Exception e) {  
141             e.printStackTrace();  
142         }  
143         return bufImg;  
144     }  
145       
146     /** 
147      * 解析二维码(QRCode) 
148      * @param imgPath 图片路径 
149      * @return 
150      */  
151     public String decoderQRCode(String imgPath) {  
152         // QRCode 二维码图片的文件  
153         File imageFile = new File(imgPath);  
154         BufferedImage bufImg = null;  
155         String content = null;  
156         try {  
157             bufImg = ImageIO.read(imageFile);  
158             QRCodeDecoder decoder = new QRCodeDecoder();  
159             content = new String(decoder.decode(new TwoDimensionCodeImage(bufImg)), "utf-8");   
160         } catch (IOException e) {  
161             System.out.println("Error: " + e.getMessage());  
162             e.printStackTrace();  
163         } catch (DecodingFailedException dfe) {  
164             System.out.println("Error: " + dfe.getMessage());  
165             dfe.printStackTrace();  
166         }  
167         return content;  
168     }  
169       
170     /** 
171      * 解析二维码(QRCode) 
172      * @param input 输入流 
173      * @return 
174      */  
175     public String decoderQRCode(InputStream input) {  
176         BufferedImage bufImg = null;  
177         String content = null;  
178         try {  
179             bufImg = ImageIO.read(input);  
180             QRCodeDecoder decoder = new QRCodeDecoder();  
181             content = new String(decoder.decode(new TwoDimensionCodeImage(bufImg)), "utf-8");   
182         } catch (IOException e) {  
183             System.out.println("Error: " + e.getMessage());  
184             e.printStackTrace();  
185         } catch (DecodingFailedException dfe) {  
186             System.out.println("Error: " + dfe.getMessage());  
187             dfe.printStackTrace();  
188         }  
189         return content;  
190     }  
191   
192     public static void main(String[] args) {  
193         String imgPath = "C:/zcpr.bmp";   //生成二维码图片存放的地址和名称
194         //String encoderContent = "Hello 大大、小小,welcome to QRCode!" + "\nMyblog [ http://sjsky.iteye.com ]" + "\nEMail [ sjsky007@gmail.com ]";  
195         String encoderContent = "http://www.baidu.com";  //二维码显示的内容
196         
197         TwoDimensionCode handler = new TwoDimensionCode();  
198         handler.encoderQRCode(encoderContent, imgPath, "png");  
199       try {  
200           OutputStream output = new FileOutputStream(imgPath);  
201           handler.encoderQRCode(encoderContent, output);  
202       } catch (Exception e) {  
203           e.printStackTrace();  
204       }  
205         System.out.println("========encoder success");  
206           
207           
208         String decoderContent = handler.decoderQRCode(imgPath);  
209         System.out.println("解析结果如下:");  
210         System.out.println(decoderContent);  
211         System.out.println("========decoder success!!!");  
212     }  
213 }  

 

转载于:https://www.cnblogs.com/hellokitty1/p/7200857.html

http://www.lbrq.cn/news/2391769.html

相关文章:

  • 网站开发存在的风险爱站网长尾关键词挖掘查询工具
  • 茶网站建设宗旨seo网络科技有限公司
  • WordPress图片方案上海外贸seo
  • 做门窗五金的网站域名注册管理机构
  • 做网站博彩代理怎么找客源seo优化sem推广
  • 企业网站建设杭州公司seo 网站推广
  • 南通网站制作昨日凌晨北京突然宣布重大消息
  • 哪儿网站建设费用低宁波营销型网站建设优化建站
  • 修改动态网站推广之家app
  • 网站开发包括几个部分余姚网站如何进行优化
  • 公司做的网站版权归谁所有百度关键词搜索引擎
  • 金华市住房建设局网站web网站设计
  • 兰州中川国际机场海外seo网站推广
  • 个人做视频网站视频储存重庆网站设计
  • wordpress如何创建导航栏河南网站推广优化
  • 张家港做网站的推荐seo网站优化案例
  • 信誉好的常州网站建设汕头seo网络推广服务
  • 电子商务网站建设实训过程2023年8月疫情恢复
  • 企业网站建站之星seo网站推广推荐
  • 大连专业做网站抖音seo优化怎么做
  • 做网站主要学什么软件免费建自己的网址
  • 网站首页制作过程百度推广客户端电脑版
  • 东莞营销型网站建设网络服务合同
  • 做网站还要买服务器吗互联网搜索引擎
  • 宝安住房和建设局网站微信朋友圈广告在哪里做
  • 分销网站有哪些深圳网站建设服务
  • 科技网站颜色企业培训课程
  • 工信部网站域名查询优化大师免费版
  • 如何做移动端网站seo技术自学
  • 可以看那种东西的浏览器seo入门黑帽培训教程
  • 《Origin画百图》之多分类矩阵散点图
  • 【Linux】基本指令
  • 物联网iot、mqtt协议与华为云平台的综合实践(万字0基础保姆级教程)
  • 辛普森悖论
  • 13.5 Meta LLaMA 2核心技术拆解:4T数据训练+30%显存优化,70B模型准确率82.6%
  • 安全事件响应分析--基础命令