博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
生成二维码
阅读量:7009 次
发布时间:2019-06-28

本文共 1434 字,大约阅读时间需要 4 分钟。

public class image {	private static final int BLACK = 0xFF000000;    private static final int WHITE = 0xFFFFFFFF;     public static void main ( String[] args ) throws Exception    {        String text = "http://47.104.160.160:8089/"; //这里是URL ,扫描之后就跳转到这个界面        String path = "D:/"; //图片生成的位置        int width = 900;        int height = 900;        // 二维码图片格式        String format = "gif";        // 设置编码,防止中文乱码        Hashtable
ht = new Hashtable
(); ht.put (EncodeHintType.CHARACTER_SET, "UTF-8"); // 设置二维码参数(编码内容,编码类型,图片宽度,图片高度,格式) BitMatrix bitMatrix = new MultiFormatWriter ().encode (text, BarcodeFormat.QR_CODE, width, height, ht); // 生成二维码(定义二维码输出服务器路径) File outputFile = new File (path); if (!outputFile.exists ()) { //创建文件夹 outputFile.mkdir (); } int b_width = bitMatrix.getWidth (); int b_height = bitMatrix.getHeight (); // 建立图像缓冲器 BufferedImage image = new BufferedImage (b_width, b_height, BufferedImage.TYPE_3BYTE_BGR); for ( int x = 0; x < b_width; x++ ) { for ( int y = 0; y < b_height; y++ ) { image.setRGB (x, y, bitMatrix.get (x, y) ? BLACK : WHITE); } } // 生成二维码 ImageIO.write (image, format, new File (path + "/img1." + format)); //二维码的名称 是 erweima.sgif }}复制代码

转载地址:http://ubitl.baihongyu.com/

你可能感兴趣的文章
Windows Server 2012 R2 WSUS-5:组策略配置自动更新
查看>>
配置SCCM 2012 SP1使用证书
查看>>
观Citrix最新官方发布评测报告有感-外行看热闹,内行看门道
查看>>
完整演示:思科IPS旁路模式的部署
查看>>
K8S集群基于heapster的HPA测试
查看>>
linux服务器集群运维经验
查看>>
Powershell-Lync:如何查询用户使用的语音策略
查看>>
《统一沟通-微软-实战》-6-部署-2-中介服务器-6-语音路由-路由
查看>>
关于CocoStudio中AtlasLabel控件后台编码的一点备注
查看>>
搞定Linux Shell文本处理工具,看完这篇集锦就够了
查看>>
Python协程深入理解
查看>>
Cocos2d-x Eclipse下程序运行产生错误Effect initCheck() returned -1
查看>>
[转] 从HTTP状态 301,302,200 来看页面跳转
查看>>
遍历Dictionary<K,V>的两种方式
查看>>
【原】Unity3d 类似Dota血条
查看>>
Spring.NET 1.3.2 集成 NHibernate 3.2 - 5 - 事务管理
查看>>
POJ 2771 Guardian of Decency(二分匹配,最大独立集)
查看>>
控制反转IOC与依赖注入DI
查看>>
sqlserver 数据库订阅报错 22202 14058
查看>>
poj 2007 Scrambled Polygon(凸多边形顶点输出)
查看>>