主要是用到了com.google.zxing jar包生成二维码的功能,这个jar包需要自己接下载

直接上代码

    public static Bitmap CreateBinaryCodeImageByUrl(String url,Bitmap bottomImg,int drawAtPointX,int drawAtPointY,int binaryCodeImgWidth)
{
try{
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType,String>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(url,BarcodeFormat.QR_CODE,binaryCodeImgWidth,binaryCodeImgWidth,hints);
int width = bottomImg.getWidth();
int height = bottomImg.getHeight();
Bitmap targetBmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int posX = 0; posX < width; posX++ ){
for( int posY = 0; posY < height; posY++){
targetBmp.setPixel(posX, posY, bottomImg.getPixel(posX, posY));
}
} int limitWidth = drawAtPointX + binaryCodeImgWidth;
int limitHeight = drawAtPointY + binaryCodeImgWidth;
for ( int posX = drawAtPointX, matrixX = 0; posX < limitWidth; posX++,matrixX++){
for( int posY = drawAtPointY, matrixY=0; posY < limitHeight; posY++,matrixY++){
targetBmp.setPixel(posX, posY, bitMatrix.get(matrixX, matrixY)?0x000000FF:0xFFFFFFFF);
}
} return targetBmp;
}
catch(Exception e){return null;
}
}

参数说明:url 就是需要转换成二维码的图片,bottomImg 就是底图,drawAtPositionX 和 drawAtPositionY 表示二维码在地图上开始绘制的坐标点(底图左上角为坐标原点)

binaryCodeImgWidth 表示生成二维码的边长

放上两个bitmap 的生成方法

//截图后保存的图片地址

Bitmap screenshotImg = BitmapFactory.decodeFile(imagePath);

//直接从资源包中取图片

InputStream shareImgStream = instance.getResources().getAssets().open(“res/xx.png”);

BitMAP screenshotImg =  BitmapFactory.decodeStream(shareImgStream);

效果如下

参考:

https://www.cnblogs.com/hongten/archive/2012/10/26/java_qrcode.html

http://www.cnblogs.com/mfrbuaa/p/5068162.html

Android 把url生成二维码并贴到给定的底图上的更多相关文章

  1. Android利用zxing生成二维码

    感谢大佬:https://blog.csdn.net/mountain_hua/article/details/80646089 **gayhub上的zxing可用于生成二维码,识别二维码 gayhu ...

  2. Android 使用zxing生成二维码的方法

    public void createQRImage(String url) { try { // 判断URL合法性 if (url == null || "".equals(url ...

  3. iOS 根据url生成二维码贴到底图上

    根据url 生成指定尺寸的二维码图片 UIImage * createBinaryCodeImg(const char * url ,CGFloat size) { //create binary c ...

  4. SpringMVC将url生成二维码图片直接展示在页面上

    利用google的开源包zxing生成二维码 第一步:maven项目的zxing依赖 <!-- google zxing 生成二维码 --> <dependency> < ...

  5. JAVA根据URL生成二维码图片、根据路径生成二维码图片

    引入jar包 zxing-2.3.0.jar.IKAnalyzer2012_u6.jar 下载地址:https://yvioo.lanzous.com/b00nlbp6h                ...

  6. 几个常用的url生成二维码的接口

    找到了几个URL生成的接口,速度上可能会有差别,可试验后选用,我用过第一个,分享: <!doctype html> <html lang="en"> < ...

  7. java url生成二维码保存到本地

    http://blog.sina.com.cn/s/blog_5a6efa330102v1lb.html http://blog.csdn.net/about58238/article/details ...

  8. java--实现将文字生成二维码图片,并在中间附上logo,下方附上文字

    前段时间因为工作需要,要实现将一段文字或者url生成二维码,然后中间附上logo,下方正中间附上文字的功能. 上网找了几篇教程学习了下,由于没有保存借鉴的博文链接,所以就没po上参考文章的链接啦,感谢 ...

  9. 通过CoreImage生成二维码

    从IOS7开始集成了二维码的生成和读取功能 生成二维码的步骤: 1.导入CoreImage框架 2.通过滤镜CIFilter生成二维码 二维码的内容(传统的条形码只能放数字): 纯文本 名片 URL ...

随机推荐

  1. Python3.7安装Geenlet

    1.首先再python文件下的Scripts文件夹下有这几个文件: 2.打开Scripts文件夹下可能你会发现是空的,这时候就要先安装setuptools了,安装完后Script文件下就出现上图的文件 ...

  2. DOM操作表单

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  3. osgEarth编译——以VS2012为例

    整理记录下 osgEarth编译过程. osgEarth是依赖于OSG的三维地理平台. 准备工作 OpenSceneGraph-3.4.0.zip OSG_3RDPARTY_DIR    http:/ ...

  4. Windows server 2008 Tips

    Tips for remote server in domain. Some Definition user [user] group workgroup domain Local account d ...

  5. 交叉编译 Cross-compiling for Linux

    @(134 - Linux) Part 1 交叉编译简介 1.1 What is cross-compiling? 对于没有做过嵌入式编程的人,可能不太理解交叉编译的概念,那么什么是交叉编译?它有什么 ...

  6. SwipeRefreshLayout 报错 dispatchTouchEvent

    今天开发android中使用了 android-suport-v4 19.1 记录 SwipeRefreshLayout 的坑: http://stackoverflow.com/questions/ ...

  7. String类型的学习

    一 :关于两个string类型变量是否相等: 请运行以下示例代码StringPool.java,查看其输出结果.如何解释这样的输出结果?从中你能总结出什么? 分析: 首先为s0开辟空间,然后给s1开辟 ...

  8. sql随机时间

    declare @endtime datetime declare @starttime datetime set @starttime='2017-09-01' set @endtime = '20 ...

  9. CSS3 transition介绍

    transition从效果上看是一种平滑过渡的动画,本质上是在线性时间内将属性从开始值过渡到结束值.例如获得焦点,点击鼠标等动作导致CSS属性值的变化是瞬间完成的,感觉有点生硬.用transition ...

  10. 面向对象进阶----->反射 getattr 和hasattr方法

    判断一个对象有没有血缘关系:isinstance() 里面写的是字类对象和父类名用来判断他们的关系 issubclass()是用来判断两个类是不是有继承的关系 ,括号内 写字类名和父类名  可以判断出 ...