主要是用到了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

最新文章

  1. c语言简易版文法
  2. EMS-Demo 雇员管理系统演示
  3. Oracle创建定时器
  4. jexus
  5. SharePoint 2013 中的SQL Server 安全
  6. xp-win7-win8的基础到精通教程-系统优化减肥教程-windos装mac
  7. 常用webshell提权方法总结
  8. java build path-&gt;source folder分析
  9. Android 获取网络状态
  10. html设置360兼容/极速模式
  11. Java中List的排序
  12. VSTS负载测试——如何:使用 SQL 创建结果存储区
  13. IOS开发-UIView之动画效果的实现方法(合集)
  14. 关于cookie与session的理解
  15. NLog日志管理工具(转)
  16. WinServer设置多用户登录
  17. 前端面试题汇总(主要为 Vue)
  18. 使用android-ndk官方ndkbuild例子
  19. yii2 basic版本的一些配置
  20. advanced ip scanner —— 局域网下 ip 及设备的扫描

热门文章

  1. 【javascript】javascript设计模式之工厂模式
  2. Arcgis GDB文件地理数据库、shapefile、coverage 和其他基于文件的数据源所支持的函数的完整列表
  3. Android沉浸式状态栏
  4. c# 获取程序目录
  5. 常用sql commands以及mysql问题解决日志
  6. resin下发布项目报错java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index
  7. C# winfrom界面跳转闪烁问题解决方法
  8. SQL查询语句执行的逻辑顺序
  9. [Swift] 使用Playground
  10. 深入探索C++对象模型(1) 关于对象(思维导图)