当前位置: 首页 > news >正文

SpringBoot生成和解析二维码完整工具类分享(提供Gitee源码)

前言:在日常的开发工作当中可能需要实现一个二维码小功能,我参考了网上很多关于SpringBoot生成二维码的教程,最终还是自己封装了一套完整生成二维码的工具类,可以支持基础的黑白二维码、带颜色的二维码、带Logo的二维码、带颜色和Logo的二维码和解析二维码五大功能,还可以生成具体的二维码文件或返回Base64,都是博主自己手写封装好的,这边免费开源给大家一键使用!只求大家一个免费的三连支持!

目录

一、问题记录

二、导入pom依赖

三、QRCodeUtil工具类完整代码

四、使用示例

五、Gitee源码

六、总结


一、问题记录

这边我使用的是zxing提供的jar包生成的二维码,不过有1个问题博客目前暂时未解决,如果有解决的方法希望可以在评论区交流一下,问题如下:

二维码的内容如果设置为中文,会报com.google.zxing.NotFoundException的错误,这个问题博主搜索了网上很多的信息也没有找到具体的解决方案。

二、导入pom依赖

    <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 二维码生成器依赖 --><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.3.0</version></dependency><dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.3.0</version></dependency><!-- 常用工具类 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

三、QRCodeUtil工具类完整代码

package com.example.ewm.utils;import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Random;
import javax.imageio.ImageIO;import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;/*** @author HTT*/
@Component
public class QRCodeUtil {/*** 编码格式*/private static final String CHARSET = "utf-8";/*** 二维码后缀名*/private static final String FORMAT_NAME = "JPG";/*** 二维码尺寸*/private static final int QRCODE_SIZE = 300;/*** 插入图宽度*/private static final int WIDTH = 60;/*** 插入图高度*/private static final int HEIGHT = 60;/*** 插入图片* @param source 文件流* @param imgPath 图片路径* @param needCompress 是否压缩图片* @throws Exception*/private void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception {File file = new File(imgPath);if (!file.exists()) {throw new Exception(imgPath+"图片文件不存在");}Image src = ImageIO.read(new File(imgPath));int width = src.getWidth(null);int height = src.getHeight(null);// 压缩LOGOif (needCompress) {if (width > WIDTH) {width = WIDTH;}if (height > HEIGHT) {height = HEIGHT;}Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics g = tag.getGraphics();// 绘制缩小后的图g.drawImage(image, 0, 0, null);g.dispose();src = image;}// 插入LOGOGraphics2D graph = source.createGraphics();int x = (QRCODE_SIZE - width) / 2;int y = (QRCODE_SIZE - height) / 2;graph.drawImage(src, x, y, width, height, null);Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);graph.setStroke(new BasicStroke(3f));graph.draw(shape);graph.dispose();}/*** 创建带图片的二维码核心方法(如果图片路径为空,不会生成图片)* @param content 二维码内容* @param imgPath 图片路径* @param needCompress 是否压缩图片* @return* @throws Exception*/private BufferedImage createEwm(String content, String imgPath, boolean needCompress) throws Exception {Hashtable hints = new Hashtable(16);hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, CHARSET);hints.put(EncodeHintType.MARGIN, 1);BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,hints);int width = bitMatrix.getWidth();int height = bitMatrix.getHeight();BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);for (int x = 0; x < width; x++) {for (int y = 0; y < height; y++) {image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);}}if (StringUtils.isEmpty(imgPath)) {return image;}// 插入图片insertImage(image, imgPath, needCompress);return image;}/*** 创建自定义颜色和图片的二维码核心方法(如果图片路径为空,不会生成图片)* @param content 二维码内容* @param imgPath 图片路径* @param needCompress 是否压缩图片* @param frontColor 前景色* @param backgroundColor 背景色* @return* @throws Exception*/private BufferedImage createEwm(String content, String imgPath, boolean needCompress,int frontColor,int backgroundColor) throws Exception {Hashtable hints = new Hashtable(16);hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, CHARSET);hints.put(EncodeHintType.MARGIN, 1);BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,hints);int width = bitMatrix.getWidth();int height = bitMatrix.getHeight();BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);for (int x = 0; x < width; x++) {for (int y = 0; y < height; y++) {image.setRGB(x, y, bitMatrix.get(x, y) ? frontColor : backgroundColor);}}if (StringUtils.isEmpty(imgPath)) {return image;}// 插入图片insertImage(image, imgPath, needCompress);return image;}/*** 生成带图片的二维码保存为文件(如果图片路径为空,不会生成图片)* @param content 二维码内容* @param imgPath 图片路径* @param destPath 存放路径* @param needCompress 是否压缩图片* @throws Exception*/private void generate(String content, String imgPath, String destPath, boolean needCompress) throws Exception {BufferedImage image = createEwm(content, imgPath, needCompress);mkdirs(destPath);ImageIO.write(image, FORMAT_NAME, new File(destPath));}/*** 创建自定义颜色和图片的二维码保存为文件(如果图片路径为空,不会生成图片)* @param content 二维码内容* @param imgPath 图片路径(路径为空,则只生成基础的二维码)* @param destPath 存放路径* @param needCompress 是否压缩图片* @param frontColor 前景色* @param backgroundColor 背景色* 例举一些16进制的颜色代码* 0x000000 黑* 0xff0000 亮红* 0x00ff00 亮绿* 0xffff00 亮黄* 0x0000ff 亮蓝* 0xff00ff 亮紫* 0x00ffff 亮浅蓝* 0xffffff 白* 0xc6c6c6 亮灰* 0x848484 暗灰* @throws Exception*/private void generate(String content, String imgPath, String destPath, boolean needCompress,int frontColor,int backgroundColor) throws Exception {BufferedImage image = createEwm(content, imgPath, needCompress,frontColor,backgroundColor);mkdirs(destPath);ImageIO.write(image, FORMAT_NAME, new File(destPath));}/*** 生成带有图片的二维码并返回Base64(如果图片路径为空,不会生成图片)* @param content 二维码内容* @param imgPath 图片路径* @param needCompress 是否压缩图片* @return* @throws Exception*/private String generateBase64(String content, String imgPath, boolean needCompress) throws Exception {if (!StringUtils.isEmpty(content)) {HashMap<EncodeHintType, Comparable> hints = new HashMap<>();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.MARGIN, 0);BufferedImage bufferedImage = createEwm(content, imgPath, needCompress);ByteArrayOutputStream os = new ByteArrayOutputStream();ImageIO.write(bufferedImage, FORMAT_NAME, os);String base64 = Base64.encode(os.toByteArray());os.flush();os.close();return "data:image/png;base64," + base64;}return "";}/*** 生成带有自定义颜色和图片的二维码并返回Base64(如果图片路径为空,不会生成图片)* @param content 二维码内容* @param imgPath 图片路径* @param needCompress 是否压缩图片* @param frontColor 前景色* @param backgroundColor 背景色* @return* @throws Exception*/private String generateBase64(String content, String imgPath, boolean needCompress,int frontColor,int backgroundColor) throws Exception {if (!StringUtils.isEmpty(content)) {HashMap<EncodeHintType, Comparable> hints = new HashMap<>();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.MARGIN, 0);BufferedImage bufferedImage = createEwm(content, imgPath, needCompress,frontColor,backgroundColor);ByteArrayOutputStream os = new ByteArrayOutputStream();ImageIO.write(bufferedImage, FORMAT_NAME, os);String base64 = Base64.encode(os.toByteArray());os.flush();os.close();return "data:image/png;base64," + base64;}return "";}/*** 创建多级目录* @param destPath*/private void mkdirs(String destPath) {File file = new File(destPath);if (!file.exists() && !file.isDirectory()) {file.mkdirs();}}/*** 根据文件解析二维码* @param file* @return* @throws Exception*/private String analysis(File file) throws Exception {BufferedImage image;image = ImageIO.read(file);if (image == null) {return null;}BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));HashMap hints = new HashMap<DecodeHintType, Object>();hints.put(DecodeHintType.CHARACTER_SET, CHARSET);Result result = new MultiFormatReader().decode(bitmap, hints);String resultStr = result.getText();return resultStr;}/*******************************************************以下是创建二维码提供的方法封装*******************************************************//******************************另存为文件版本******************************//*** 创建基础的二维码* @param content 二维码内容* @param destPath 存放路径* @throws Exception*/public void create(String content, String destPath) throws Exception {generate(content, null, destPath, false);}/*** 创建带颜色基础的二维码* @param content 二维码内容* @param destPath 存放路径* @throws Exception*/public void create(String content, String destPath,int frontColor,int backgroundColor) throws Exception {generate(content, null, destPath, false,frontColor,backgroundColor);}/*** 创建带图片的二维码* @param content 二维码内容* @param imgPath 图片路径* @param destPath 存放路径* @param needCompress 是否压缩图片* @throws Exception*/public void create(String content, String imgPath, String destPath,boolean needCompress) throws Exception {generate(content, imgPath, destPath, needCompress);}/*** 创建带有自定义颜色和图片的二维码* @param content 二维码内容* @param imgPath 图片路径* @param destPath 存放路径* @param needCompress 是否压缩图片* @param frontColor 前景色* @param backgroundColor 背景色* @throws Exception*/public void create(String content, String imgPath, String destPath,boolean needCompress,int frontColor,int backgroundColor) throws Exception {generate(content, imgPath, destPath, needCompress,frontColor,backgroundColor);}/******************************另存为文件版本******************************//******************************Base64版本******************************//*** 创建基础的二维码并返回Base64* @param content* @throws Exception*/public String create(String content) throws Exception {return generateBase64(content,null,false);}/*** 创建带颜色基础的二维码并返回Base64* @param content* @throws Exception*/public String create(String content,int frontColor,int backgroundColor) throws Exception {return generateBase64(content,null,false,frontColor,backgroundColor);}/*** 创建带图片的二维码并返回Base64* @param content 二维码内容* @param imgPath 图片路径* @param needCompress 是否压缩图片* @throws Exception*/public String create(String content, String imgPath,boolean needCompress) throws Exception {return generateBase64(content, imgPath, needCompress);}/*** 创建带有自定义颜色和图片的二维码并返回Base64* @param content 二维码内容* @param imgPath 图片路径* @param needCompress 是否压缩图片* @param frontColor 前景色* @param backgroundColor 背景色* @throws Exception*/public String create(String content, String imgPath,boolean needCompress,int frontColor,int backgroundColor) throws Exception {return generateBase64(content, imgPath, needCompress,frontColor,backgroundColor);}/******************************Base64版本******************************//*** 根据文件路径解析二维码* @param path 文件路径* @return* @throws Exception*/public String decode(String path) throws Exception {File file = new File(path);if(!file.exists()){throw new Exception("文件不存在!");}return analysis(file);}}

四、使用示例

友情提醒:代码中的布尔值是代表Logo图片是否需要被压缩,如果是true说明嵌入的Logo图片需要被压缩,我的建议是默认为true,因为如果不压缩,在使用decode解析带Logo的二维码的时候会报com.google.zxing.NotFoundException的错误,博主亲自测试过。

单元测试:

@SpringBootTest
class EwmApplicationTests {@Resourceprivate QRCodeUtil qrCodeUtil;@Testvoid contextLoads() throws Exception {qrCodeUtil.create("httstudy","F:\\基础二维码.jpg");qrCodeUtil.create("httstudy","F:\\带颜色的二维码.jpg",0xff0000,0xffff00);qrCodeUtil.create("httstudy","F:\\Logo.png","F:\\带logo的二维码.jpg",true);qrCodeUtil.create("httstudy","F:\\Logo.png","F:\\带颜色和logo的二维码.jpg",true,0xff0000,0xffff00);String str = qrCodeUtil.create("httstudy");String str2 = qrCodeUtil.create("httstudy",0xff0000,0xffff00);String str3 = qrCodeUtil.create("httstudy","F:\\Logo.png",true);String str4 = qrCodeUtil.create("httstudy","F:\\Logo.png",true,0xff0000,0xffff00);System.out.println(str);System.out.println(str2);System.out.println(str3);System.out.println(str4);String result = qrCodeUtil.decode("F:\\基础二维码.jpg");String result2 = qrCodeUtil.decode("F:\\带颜色的二维码.jpg");String result3 = qrCodeUtil.decode("F:\\带logo的二维码.jpg");String result4 = qrCodeUtil.decode("F:\\带颜色和logo的二维码.jpg");System.out.println(result);System.out.println(result2);System.out.println(result3);System.out.println(result4);}}

 运行结果:

五、Gitee源码

码云地址:SpringBoot生成二维码完整工具类分享

六、总结

良心博主原创封装不易,把常见场景需要用到的二维码类型都给大家封装好了,只要像单元测试那样一键生成就好了,如有问题,欢迎评论区留言!

相关文章:

SpringBoot生成和解析二维码完整工具类分享(提供Gitee源码)

前言&#xff1a;在日常的开发工作当中可能需要实现一个二维码小功能&#xff0c;我参考了网上很多关于SpringBoot生成二维码的教程&#xff0c;最终还是自己封装了一套完整生成二维码的工具类&#xff0c;可以支持基础的黑白二维码、带颜色的二维码、带Logo的二维码、带颜色和…...

Redis的基本知识(偏八股)

前言 本文篇概念&#xff0c;着重介绍Redis的执行效率、功能作用、数据类型、 执行效率 江湖上都流传这Redis的执行效率是挺快的&#xff0c;那为什么说它快呢&#xff1f;有以下几个原因&#xff1a; 基于内存单线程模型高效数据结构非阻塞I/O 基于内存: 内存的读写效率是…...

react使用antd的table组件,实现点击弹窗显示对应列的内容

特别提醒&#xff1a;不能在table的columns的render里面设置弹窗组件渲染&#xff0c;因为这会导致弹窗显示的始终是最后一行的内容&#xff0c;因为这样渲染的结果是每一行都会重新渲染一遍这个弹窗并且会给传递一个content的值&#xff0c;渲染到最后一行的时候&#xff0c;就…...

c++代码代码逻辑走查

自助生物采集代码 C部分流程...

CSS scoped 属性的原理

scoped 一、scoped 是什么&#xff1f;二、实现原理 一、scoped 是什么&#xff1f; 在 Vue 组件中&#xff0c;为了使样式私有化&#xff08;模块化&#xff09;&#xff0c;不对全局造成污染&#xff0c;可以在 style 标签上添加 scoped 属性以表示它的只属于当下的模块&am…...

git 查看某个分支是从哪个分支拉出来的

原文链接&#xff1a;https://blog.csdn.net/allanGold/article/details/102478157 git reflog show 分支名git reflog --datelocal | grep 分支名git reflog --datelocal | grep 分支名 $ git reflog --datelocal | grep release3 5c50761 HEAD{Thu Jun 29 12:53:45 2023}: c…...

vue helloworld.vue 点击按钮弹出 dialog,并给dialog传值

1 DataAnalysisVue.Vue -->应该组件文件名和 name: 的名字一致 <template><div><el-dialog :title"dataAnalysisMsg" :visible.sync"dataAnalysisvalue" :before-close"handleClose"><span>{{ dataAnalysisMsg }}&l…...

html动态爱心代码【三】(附源码)

目录 前言 特效 内容修改 完整代码 总结 前言 七夕马上就要到了&#xff0c;为了帮助大家高效表白&#xff0c;下面再给大家带来了实用的HTML浪漫表白代码(附源码)背景音乐&#xff0c;可用于520&#xff0c;情人节&#xff0c;生日&#xff0c;表白等场景&#xff0c;可直…...

mmseg——报错解决:RuntimeError: CUDA error: an illegal memory access was encountered

可能解决方法汇总 GitHub issue相关汇总RuntimeError: CUDA error while trainingCUDA error: an illegal memory access was encountered记录使用mmseg时在计算交叉熵损失遇到的RuntimeError问题与解决方案...

AWS复制EC2文件到S3,g4dn.2xlarge没有NVIDIA GPU 驱动问题

1、给instances权限 action > Security > modify IAM role 把提前创建好的role给这个instance即可 2、复制到bucket aws s3 cp gogo.tar.gz s3://ee547finalbucket不需要手动安装GPU驱动 如果要自己安装&#xff0c;参考https://docs.aws.amazon.com/AWSEC2/latest/U…...

Go语言GIN框架安装与入门

Go语言GIN框架安装与入门 文章目录 Go语言GIN框架安装与入门1. 创建配置环境2. 配置环境3. 下载最新版本Gin4. 编写第一个接口5. 静态页面和资源文件加载6. 各种传参方式6.1 URL传参6.2 路由形式传参6.3 前端给后端传递JSON格式6.4 表单形式传参 7. 路由和路由组8. 项目代码mai…...

低代码系列——初步认识低代码

低代码系列目录 一、初步认识低代码 二、低代码是什么 三、低代码平台的概念和分类 01.无代码开发平台 02.低代码应用平台(LCAP) 03.多重体验开发平台(MXDP) 04.智能业务流程管理套件(iBPMS) 四、低代码的能力指标 五、低代码平台jnpf 表单 报表 流程 权限 一、初步认识低代码 …...

从陌生到熟练使用string类

&#x1f388;个人主页:&#x1f388; :✨✨✨初阶牛✨✨✨ &#x1f43b;推荐专栏1: &#x1f354;&#x1f35f;&#x1f32f;C语言初阶 &#x1f43b;推荐专栏2: &#x1f354;&#x1f35f;&#x1f32f;C语言进阶 &#x1f511;个人信条: &#x1f335;知行合一 &#x1f…...

ERP规划

ERP规划是指一个组织或企业在实施企业资源计划&#xff08;ERP&#xff09;系统之前&#xff0c;对其整体目标、需求和资源进行评估和规划的过程。以下是ERP规划的一般步骤和要点&#xff1a; 制定目标&#xff1a;明确组织对ERP系统的期望和目标&#xff0c;例如提高经营效率、…...

统计学作业啊啊啊啊

题目1 一个制药公司宣称其新药可以将病患的恢复时间从10天降至8天。为了验证这一声明&#xff0c;您从服用新药的病患中抽取了一个样本&#xff0c;发现样本均值为9天&#xff0c;样本标准差为2天&#xff0c;样本量为30。使用0.05的显著性水平进行假设检验&#xff0c;判断公…...

CAM实现的流程--基于Pytorch实现

CAM实现的流程 CAM类激活映射CAM是什么CAM与CNN CAM类激活映射 CAM是什么 可视化CNN的工具&#xff0c; CAM解释网络特征变化&#xff0c;CAM使得弱监督学习发展成为可能&#xff0c;可以慢慢减少对人工标注的依赖&#xff0c;能降低网络训练的成本。通过可视化&#xff0c;就…...

FL Studio2023最新版本21.1中文水果音乐编曲工具

虚拟乐器和真实乐器的区别&#xff1f;真实乐器指的是现实中需要乐手演奏的乐器&#xff0c;而虚拟乐器是计算机音乐制作中编曲师使用的数字乐器。FL Studio虚拟乐器插件有哪些&#xff1f;下文将给大家介绍几款FL Studio自带的强大虚拟乐器。 一、虚拟乐器和真实乐器的区别 …...

数据库概述SQL基本语法

基本概念 数据库DB database简称DB: 存储数据的仓库&#xff0c;是以某种结构存储数据的文件。指长期保存在计算机的存储设备上&#xff0c;按照一定规则阻止起来&#xff0c;可以被用户或应用共享的数据集合。 数据库管理系统DBMS 用于创建&#xff0c;维护&#xff0c;使…...

【面试】一文讲清组合逻辑中的竞争与冒险

竞争的定义&#xff1a;组合逻辑电路中&#xff0c;输入信号的变化传输到电路的各级逻辑门&#xff0c;到达的时间有先后&#xff0c;也就是存在时差&#xff0c;称为竞争。 冒险的定义&#xff1a;当输入信号变化时&#xff0c;由于存在时差&#xff0c;在输出端产生错误&…...

无涯教程-PHP - 性能优化

根据Zend小组的说明,以下插图显示了PHP 7与PHP 5.6和基于流行的基于PHP的应用程序上的HHVM 3.7。 Magento 1.9 与执行Magento事务的PHP 5.6相比&#xff0c;PHP 7的运行速度证明是其两倍。 Drupal 7 在执行Drupal事务时&#xff0c;与PHP 5.6相比&#xff0c;PHP 7的运行速度…...

k8s从入门到放弃之Ingress七层负载

k8s从入门到放弃之Ingress七层负载 在Kubernetes&#xff08;简称K8s&#xff09;中&#xff0c;Ingress是一个API对象&#xff0c;它允许你定义如何从集群外部访问集群内部的服务。Ingress可以提供负载均衡、SSL终结和基于名称的虚拟主机等功能。通过Ingress&#xff0c;你可…...

大型活动交通拥堵治理的视觉算法应用

大型活动下智慧交通的视觉分析应用 一、背景与挑战 大型活动&#xff08;如演唱会、马拉松赛事、高考中考等&#xff09;期间&#xff0c;城市交通面临瞬时人流车流激增、传统摄像头模糊、交通拥堵识别滞后等问题。以演唱会为例&#xff0c;暖城商圈曾因观众集中离场导致周边…...

前端导出带有合并单元格的列表

// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

使用van-uploader 的UI组件,结合vue2如何实现图片上传组件的封装

以下是基于 vant-ui&#xff08;适配 Vue2 版本 &#xff09;实现截图中照片上传预览、删除功能&#xff0c;并封装成可复用组件的完整代码&#xff0c;包含样式和逻辑实现&#xff0c;可直接在 Vue2 项目中使用&#xff1a; 1. 封装的图片上传组件 ImageUploader.vue <te…...

06 Deep learning神经网络编程基础 激活函数 --吴恩达

深度学习激活函数详解 一、核心作用 引入非线性:使神经网络可学习复杂模式控制输出范围:如Sigmoid将输出限制在(0,1)梯度传递:影响反向传播的稳定性二、常见类型及数学表达 Sigmoid σ ( x ) = 1 1 +...

初学 pytest 记录

安装 pip install pytest用例可以是函数也可以是类中的方法 def test_func():print()class TestAdd: # def __init__(self): 在 pytest 中不可以使用__init__方法 # self.cc 12345 pytest.mark.api def test_str(self):res add(1, 2)assert res 12def test_int(self):r…...

JVM 内存结构 详解

内存结构 运行时数据区&#xff1a; Java虚拟机在运行Java程序过程中管理的内存区域。 程序计数器&#xff1a; ​ 线程私有&#xff0c;程序控制流的指示器&#xff0c;分支、循环、跳转、异常处理、线程恢复等基础功能都依赖这个计数器完成。 ​ 每个线程都有一个程序计数…...

jmeter聚合报告中参数详解

sample、average、min、max、90%line、95%line,99%line、Error错误率、吞吐量Thoughput、KB/sec每秒传输的数据量 sample&#xff08;样本数&#xff09; 表示测试中发送的请求数量&#xff0c;即测试执行了多少次请求。 单位&#xff0c;以个或者次数表示。 示例&#xff1a;…...

android RelativeLayout布局

<?xml version"1.0" encoding"utf-8"?> <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"android:layout_width"match_parent"android:layout_height"match_parent"android:gravity&…...

WebRTC调研

WebRTC是什么&#xff0c;为什么&#xff0c;如何使用 WebRTC有什么优势 WebRTC Architecture Amazon KVS WebRTC 其它厂商WebRTC 海康门禁WebRTC 海康门禁其他界面整理 威视通WebRTC 局域网 Google浏览器 Microsoft Edge 公网 RTSP RTMP NVR ONVIF SIP SRT WebRTC协…...