热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

直播视频app源码,Android点击生成二维码

直播视频app源码,Android点击生成二维码实现的相关代码activity.xml代码如下:

直播视频app源码,Android 点击生成二维码实现的相关代码
activity.xml代码如下:

<?xml version&#61;"1.0" encoding&#61;"utf-8"?>
<LinearLayout xmlns:android&#61;"http://schemas.android.com/apk/res/android"android:layout_width&#61;"match_parent"android:layout_height&#61;"match_parent"android:orientation&#61;"vertical"><EditTextandroid:id&#61;"&#64;&#43;id/create_qr_content"android:layout_width&#61;"match_parent"android:layout_height&#61;"wrap_content" /><LinearLayoutandroid:layout_width&#61;"match_parent"android:layout_height&#61;"wrap_content"android:orientation&#61;"horizontal"><Buttonandroid:id&#61;"&#64;&#43;id/create_qr_btn"android:layout_width&#61;"wrap_content"android:layout_height&#61;"wrap_content"android:text&#61;"生成二维码" /><CheckBoxandroid:id&#61;"&#64;&#43;id/create_qr_addLogo"android:layout_width&#61;"wrap_content"android:layout_height&#61;"wrap_content"android:text&#61;"添加logo图案" /></LinearLayout><ImageViewandroid:id&#61;"&#64;&#43;id/create_qr_iv"android:layout_width&#61;"match_parent"android:layout_height&#61;"wrap_content" />
</LinearLayout>

QRCodeUtil工具类

public class QRCodeUtil {public static boolean createQRImage(String content, int widthPix, int heightPix, Bitmap logoBm, String filePath) {try {if (content &#61;&#61; null || "".equals(content)) {return false;}//配置参数Map<EncodeHintType, Object> hints &#61; new HashMap<>();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//容错级别hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);//设置空白边距的宽度
// hints.put(EncodeHintType.MARGIN, 2); //default is 4// 图像数据转换&#xff0c;使用了矩阵转换BitMatrix bitMatrix &#61; new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix, heightPix, hints);int[] pixels &#61; new int[widthPix * heightPix];// 下面这里按照二维码的算法&#xff0c;逐个生成二维码的图片&#xff0c;// 两个for循环是图片横列扫描的结果for (int y &#61; 0; y < heightPix; y&#43;&#43;) {for (int x &#61; 0; x < widthPix; x&#43;&#43;) {if (bitMatrix.get(x, y)) {pixels[y * widthPix &#43; x] &#61; 0xff000000;} else {pixels[y * widthPix &#43; x] &#61; 0xffffffff;}}}// 生成二维码图片的格式&#xff0c;使用ARGB_8888Bitmap bitmap &#61; Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);if (logoBm !&#61; null) {bitmap &#61; addLogo(bitmap, logoBm);}//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的&#xff0c;内存消耗巨大&#xff01;return bitmap !&#61; null && bitmap.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(filePath));} catch (WriterException | IOException e) {e.printStackTrace();}return false;}/*** 在二维码中间添加Logo图案*/private static Bitmap addLogo(Bitmap src, Bitmap logo) {if (src &#61;&#61; null) {return null;}if (logo &#61;&#61; null) {return src;}//获取图片的宽高int srcWidth &#61; src.getWidth();int srcHeight &#61; src.getHeight();int logoWidth &#61; logo.getWidth();int logoHeight &#61; logo.getHeight();if (srcWidth &#61;&#61; 0 || srcHeight &#61;&#61; 0) {return null;}if (logoWidth &#61;&#61; 0 || logoHeight &#61;&#61; 0) {return src;}//logo大小为二维码整体大小的1/5float scaleFactor &#61; srcWidth * 1.0f / 5 / logoWidth;Bitmap bitmap &#61; Bitmap.createBitmap(srcWidth, srcHeight, Bitmap.Config.ARGB_8888);try {Canvas canvas &#61; new Canvas(bitmap);canvas.drawBitmap(src, 0, 0, null);canvas.scale(scaleFactor, scaleFactor, srcWidth / 2, srcHeight / 2);canvas.drawBitmap(logo, (srcWidth - logoWidth) / 2, (srcHeight - logoHeight) / 2, null);canvas.save();canvas.restore();} catch (Exception e) {bitmap &#61; null;e.getStackTrace();}return bitmap;}
}

Activity 代码如下

&#64;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_shop);//内容final EditText contentET &#61; (EditText) findViewById(R.id.create_qr_content);//显示二维码图片final ImageView imageView &#61; (ImageView) findViewById(R.id.create_qr_iv);//是否添加Logofinal CheckBox addLogoCB &#61; (CheckBox) findViewById(R.id.create_qr_addLogo);Button createQrBtn &#61; (Button) findViewById(R.id.create_qr_btn);createQrBtn.setOnClickListener(new View.OnClickListener() {&#64;Overridepublic void onClick(View v) {final String filePath &#61; getFileRoot(ShopActivity.this) &#43; File.separator&#43; "qr_" &#43; System.currentTimeMillis() &#43; ".jpg";//二维码图片较大时&#xff0c;生成图片、保存文件的时间可能较长&#xff0c;因此放在新线程中new Thread(new Runnable() {&#64;Overridepublic void run() {boolean success &#61; QRCodeUtil.createQRImage(contentET.getText().toString().trim(), 800, 800,addLogoCB.isChecked() ? BitmapFactory.decodeResource(getResources(), R.mipmap.heartsong) : null,filePath);if (success) {runOnUiThread(new Runnable() {&#64;Overridepublic void run() {imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));}});}}}).start();}});}//文件存储根目录private String getFileRoot(Context context) {if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {File external &#61; context.getExternalFilesDir(null);if (external !&#61; null) {return external.getAbsolutePath();}}return context.getFilesDir().getAbsolutePath();}

以上就是直播视频app源码&#xff0c;Android 点击生成二维码实现的相关代码&#xff0c; 更多内容欢迎关注之后的文章


推荐阅读
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • r2dbc配置多数据源
    R2dbc配置多数据源问题根据官网配置r2dbc连接mysql多数据源所遇到的问题pom配置可以参考官网,不过我这样配置会报错我并没有这样配置将以下内容添加到pom.xml文件d ... [详细]
author-avatar
syjs10
这个家伙很懒
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有