微信扫描二维码跳转页面
2016-07-04 10:52
549 查看
最近在完成一个大作业,反正一个小部分就是扫描二维码,跳转到一个界面去,搜网上也没有什么太有用的信息,觉得难死了。。 后来想想,以前写过一个程序,就是把字符串生成相应的二维码,然后我就抱着试试看的心态,把url 放进去,扫一下看看,结果,成功了。。。瞎猫碰着死老鼠,真幸运~~
可以参考我的这篇文章:http://blog.csdn.net/prayallforyou/article/details/51417807
public class test {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
public static void main ( String[] args ) throws Exception
{
String text = "https://www.baidu.com/"; //这里是URL ,扫描之后就跳转到这个界面
String path = "D:/"; //图片生成的位置
int width = 900;
int height = 900;
// 二维码图片格式
String format = "gif";
// 设置编码,防止中文乱码
Hashtable<EncodeHintType, Object> ht = new Hashtable<EncodeHintType, Object> ();
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 + "/erweima." + format)); //二维码的名称 是 erweima.sgif
}
}
可以参考我的这篇文章:http://blog.csdn.net/prayallforyou/article/details/51417807
public class test {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
public static void main ( String[] args ) throws Exception
{
String text = "https://www.baidu.com/"; //这里是URL ,扫描之后就跳转到这个界面
String path = "D:/"; //图片生成的位置
int width = 900;
int height = 900;
// 二维码图片格式
String format = "gif";
// 设置编码,防止中文乱码
Hashtable<EncodeHintType, Object> ht = new Hashtable<EncodeHintType, Object> ();
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 + "/erweima." + format)); //二维码的名称 是 erweima.sgif
}
}
相关文章推荐
- 社交巨头三国杀:微信、WhatsApp、Line到底有啥区别?
- java-用HttpURLConnection发送Http请求.
- 微信悄悄升级群聊功能:个人微信营销号的福音
- 突击部队拼多多
- 我是运营,我没有假期
- 如何做到日消息量100万的微信公众号?
- 论微信取消推送功能的可能性(原创)
- 微信的成功,靠的是QQ导流吗?
- 「Linux 中国」2018 微信文章排行榜
- 马化腾亲自“站台” 企业微信和个人微信互通能带来什么?
- 一个微信群的兴亡
- VBScript 剪贴板抓取URL并在浏览器中打开
- 微信服务号推送模板消息接口
- 用vbs 实现从剪贴板中抓取一个 URL 然后在浏览器中打开该 Web 站点
- C#微信公众号与订阅号接口开发示例代码