首页 技术 正文
技术 2022年11月19日
0 收藏 462 点赞 3,017 浏览 1533 个字

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

效果如下

Android 把url生成二维码并贴到给定的底图上

参考:

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

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905