二维码图片流转base64
@RequestMapping(value = "/weChatImage",method = RequestMethod.GET)
public Response weChatimage(@RequestParam(required=false) int width,@RequestParam(required=false) int height,@RequestParam(required = false) String redirect, HttpServletResponse response) throws Exception{ String code = java.util.UUID.randomUUID().toString();
String code_url = SystemProperties.getValue("ucenter.out.url")+"/weChat/scanCode?state="+code;
//String code_url = "http://localhost:8080/weChat/scanCode?state="+code;
Map<String,Object> map1 = new HashMap<>();
map1.put("redirect",redirect);
redis.opsForValue().set(code,JSON.toJSONString(map1),7,TimeUnit.DAYS); if(width == 0){
width = 200;//宽度
}
if(height == 0){
height = 200;//高度
} Map<EncodeHintType,Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); //生成矩阵
BitMatrix bitMatrix = new MultiFormatWriter().encode(code_url, BarcodeFormat.QR_CODE, width, height, hints); //字节数组输出流
ByteArrayOutputStream imageOut = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "png", imageOut); //字节数组输入流
ByteArrayInputStream imageIn = new ByteArrayInputStream(imageOut.toByteArray());
BufferedImage bImage = ImageIO.read(imageIn); ByteArrayOutputStream bs =new ByteArrayOutputStream();
ImageIO.write(bImage, "png", bs); String base64 = "data:image/png;base64,"+Base64.byteArrayToBase64(bs.toByteArray());
Map<String,Object> map = new HashMap<>();
map.put("base64",base64);
map.put("url",code_url);
map.put("code",code); return Response.newInstance().setStatus(Response.SUCCESS).setBody(map);
}
二维码图片流转base64的更多相关文章
- 随手记一次利用开源zxing生成带嵌入logo的二维码图片
之前就在项目里面用过zxing生成二维码,最近另一个项目同样需要用到二维码,故重新在学了学利用zxing生成二维码 接下来先做准备工作了,因为我是用vs2013上开发的,故选择了.net4.5版本的z ...
- 使用javascript生成当前博文地址的二维码图片
前面的话 在电脑端发现一篇好的博文,想在手机上访问.这时,就必须打开手机浏览器输入长长的URL地址才行,非常不方便.如果在博客标题的后面跟一张小的图片,点击该图片后,出现一张二维码的大图,然后再通过手 ...
- qrCode生成二维码图片
QRCode.js 是一个用于生成二维码图片的插件. 1.文件脚本 var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,th ...
- vue2.0生成二维码图片并且下载图片到本地兼容写法
vue生成二维码图片,这里使用的是qrcode.js 这个插件(亲测写法,兼容没有问题) 第一步,下载插件 需要注意,这里下载的是qrcodejs2 cnpm install --save qrcod ...
- python将url转变成二维码图片
将url数据转变成二维码数据,再将二维码图片转成base64格式返回 import qrcode import io def url_image(self,url): img = qrcode.mak ...
- online QRcode generator , QRcode=== (Quick Response Code) , 二维条码,二维码,彩色二维码,图片二维码,
online QRcode generator , QRcode=== (Quick Response Code) , 二维条码,二维码,彩色二维码,图片二维码, 1 http://cli.i ...
- 使用google zxing生成二维码图片
生成二维码工具类: 1 import java.awt.geom.AffineTransform; 2 import java.awt.image.AffineTransformOp; 3 impor ...
- JAVA生成二维码图片代码
首先需要导入 QRCode.jar 包 下载地址看这里 http://pan.baidu.com/s/1o6qRFqM import java.awt.Color;import java.awt. ...
- java--实现将文字生成二维码图片,并在中间附上logo,下方附上文字
前段时间因为工作需要,要实现将一段文字或者url生成二维码,然后中间附上logo,下方正中间附上文字的功能. 上网找了几篇教程学习了下,由于没有保存借鉴的博文链接,所以就没po上参考文章的链接啦,感谢 ...
随机推荐
- 使用ssh从外网访问内网
一.场景如下: 各个角色的对应关系如下: 角色 描述 APP 个人笔记本,属于内网IP sshd server 公网 VPS ( 映射端口: port 2222 ),拥有公网IP ssh client ...
- ADO.NET-temple
ylbtech-ADO.NET:ADO.NET-Oracle|SQLServer|MySql|Access|Excel-dddd 介绍及讲解 1.A,插入数据(Create) 1.B,读取数据(Rea ...
- Swift 函数的定义与调用(Defining and Calling Functions)
当你定义一个函数时,你能够定义一个或多个有名字和类型的值.作为函数的输入(称为參数.parameters).也能够定义某种类型的值作为函数运行结束的输出(称为返回类型). 每一个函数有个函数名,用来描 ...
- lampp、xampp安装文档
第一步:去官网 看这个介绍http://www.apachefriends.org/zh_cn/xampp-linux.html#1677 第二步:下载安装包 2.1 要区分Linux是32位还是64 ...
- SourceTree的基本使用-git on mac
SourceTree的基本使用 学习了:https://www.cnblogs.com/tian-xie/p/6264104.html
- CodeForces - 344B Simple Molecules (模拟题)
CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...
- 115. distinct subsequence leetcode python
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- Win7如何解决精简版的迅雷7无法运行
网上下载msvcp71.dll和msvcr71.dll把文件放到System32目录下即可 http://www.baidu.com/s?wd=msvcp71.dll&ie=utf-8&a ...
- Asp 解析 XML并分页显示
Asp 解析 XML并分页显示 Asp 解析 XML并分页显示,演示样例源代码例如以下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...
- TextView上的文字逐渐变淡直到消失
给TextView加个动画效果,完了在个动画加个监听,里面有个动画执行完调用的方法在方法里面把TextView设置为gone,我觉得你直接加这个动画效果之后他就会不显示了,其实他还在那占有位置呢.想不 ...