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

Unity之创建与导出PDF

内容将会持续更新,有错误的地方欢迎指正,谢谢!
 

Unity之创建与导出PDF
     
TechX 坚持将创新的科技带给世界!

拥有更好的学习体验 —— 不断努力,不断进步,不断探索
TechX —— 心探索、心进取!

助力快速掌握 PDF 的创建与导出

为初学者节省宝贵的学习时间,避免困惑!


TechX 教程效果:

在这里插入图片描述


文章目录

  • 一、第三方库iTextSharp导入
    • 1、通过Visual Studio的NuGet包管理器下载iTextSharp库
    • 2、导入DLL文件到Unity中
  • 二、使用iTextSharp生成和写入PDF文件的示例
  • 三、写入和导出PDF实战


一、第三方库iTextSharp导入


在Unity中生成PDF文件并写入内容,需要使用第三方库,因为Unity本身不提供直接操作PDF的API。一个常用的库是iTextSharp,这是一个强大的PDF处理库。iTextSharp是iText的C#版本,可以用于创建、修改和读取PDF文档。

1、通过Visual Studio的NuGet包管理器下载iTextSharp库


  1. 打开NuGet包管理器:

    在Visual Studio中,点击Tools菜单,选择NuGet Package Manager,然后选择Manage NuGet Packages for Solution…。

  2. 搜索iTextSharp:

    在打开的NuGet包管理器窗口中,点击Browse选项卡,然后在搜索框中输入iTextSharp。

  3. 安装iTextSharp:

    在搜索结果中找到iTextSharp包,点击Install按钮进行安装。根据提示完成安装过程。

在这里插入图片描述

2、导入DLL文件到Unity中


上一步下载的iTextSharp包在工程目录的Packages下,共包含两个文件夹:BouncyCastle.Cryptography.2.4.0和iTextSharp.5.5.13.4。

在这里插入图片描述

进入BouncyCastle.Cryptography.2.4.0\lib\net461和iTextSharp.5.5.13.4\lib\net461目录中找到BouncyCastle.Cryptography.dll和itextsharp.dll

在这里插入图片描述

将两个DLL文件复制到你的Unity项目的Assets/Plugins文件夹中。如果没有Plugins文件夹,可以创建一个。

在这里插入图片描述



二、使用iTextSharp生成和写入PDF文件的示例


在Unity项目中创建一个C#脚本,例如PDFGenerator.cs。

在脚本中使用iTextSharp来生成和写入PDF。

以下是完整的示例代码:

using UnityEngine;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Image = iTextSharp.text.Image;public class PDFGenerator : MonoBehaviour
{void Start(){// 设置PDF保存路径string path = Application.dataPath + "/GeneratedPDF.pdf";// 图片路径string imgPath = Application.streamingAssetsPath+ "/path_to_image.jpg";using (FileStream fileStream = new FileStream(path, FileMode.Create)){// 创建一个文档对象Document document = new Document();// 创建一个PDF写入流PdfWriter pdfWriter = PdfWriter.GetInstance(document, fileStream );// 打开文档document.Open();// 添加内容到文档document.Add(new Paragraph("Hello, World!"));document.Add(new Paragraph("This is a PDF generated in Unity."));// 添加图片Image image = Image.GetInstance(imgPath );document.Add(image);// 添加表格PdfPTable table = new PdfPTable(3); // 3列的表格table.AddCell("Cell 1");table.AddCell("Cell 2");document.Add(table);//关闭写入流pdfWriter.Close();// 关闭文档document.Close();}Debug.Log("PDF generated at: " + path);}
}


三、写入和导出PDF实战


using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using UnityEngine;
using Font = iTextSharp.text.Font;
using Rectangle = iTextSharp.text.Rectangle;namespace PDFExport
{/// <summary>/// PDF文档操作类/// </summary>public class PDFOperation{#region 私有字段private Font font = default;private PdfWriter pdfWriter;private Rectangle documentSize;   //文档大小private Document document;//文档对象private BaseFont basefont;//字体#endregion#region 构造函数/// <summary>/// 构造函数/// </summary>public PDFOperation(){documentSize = PageSize.A4;document = new Document(documentSize);}/// <summary>/// 构造函数/// </summary>/// <param name="type">页面大小(如"A4")</param>public PDFOperation(Rectangle size){documentSize = size;document = new Document(size);}/// <summary>/// 构造函数/// </summary>/// <param name="type">页面大小(如"A4")</param>/// <param name="marginLeft">内容距左边框距离</param>/// <param name="marginRight">内容距右边框距离</param>/// <param name="marginTop">内容距上边框距离</param>/// <param name="marginBottom">内容距下边框距离</param>public PDFOperation(Rectangle size, float marginLeft, float marginRight, float marginTop, float marginBottom){documentSize = size;document = new Document(size, marginLeft, marginRight, marginTop, marginBottom);}#endregion#region 文档操作/// <summary>/// 创建写入流/// </summary>/// <param name="os">文档相关信息(如路径,打开方式等)</param>public PdfWriter OpenPdfWriter(FileStream os){pdfWriter = PdfWriter.GetInstance(document, os);return pdfWriter;}/// <summary>/// 关闭写入流/// </summary>/// <param name="writer"></param>public void ClosePdfWriter(){pdfWriter.Close();}/// <summary>/// 打开文档/// </summary>public void Open(){document.Open();}/// <summary>/// 关闭打开的文档/// </summary>public void Close(){document.Close();}#endregion#region 设置字体/// <summary>/// 设置字体/// </summary>public void SetBaseFont(string path){basefont = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);}/// <summary>/// 设置字体/// </summary>/// <param name="size">字体大小</param>public Font SetFont(float size){font = new Font(basefont, size);return font;}/// <summary>/// 设置字体/// </summary>/// <param name="size"></param>/// <param name="style"></param>public Font SetFont(float size, int style){font = new Font(basefont, size, style);return font;}/// <summary>/// 设置字体/// </summary>/// <param name="size"></param>/// <param name="style"></param>/// <param name="fontColor"></param>public Font SetFont(float size, int style, BaseColor fontColor){font = new Font(basefont, size, style, fontColor);return font;}/// <summary>/// 获取字体/// </summary>/// <returns></returns>public Font GetFont(){return font;}#endregionpublic void AddPage(){document.NewPage();}#region 添加段落/// <summary>/// 空格/// 加入空行,用以区分上下行/// </summary>public void AddNullLine(int nullLine=1,int lightHeight=12){// Change this to the desired number of empty linesint numberOfEmptyLines = nullLine; for (int i = 0; i < numberOfEmptyLines; i++){Paragraph emptyLine = new Paragraph(" ", new Font(Font.FontFamily.HELVETICA, lightHeight));document.Add(emptyLine);}}/// <summary>/// 插入文字内容/// </summary>/// <param name="content">内容</param>/// <param name="alignmentType">对齐格式,0为左对齐,1为居中</param>/// <param name="indent">首行缩进</param>public void AddParagraph(string content, int alignmentType = 0,float indent = 0){Paragraph contentP = new Paragraph(new Chunk(content, font));contentP.FirstLineIndent = indent;contentP.Alignment = alignmentType;document.Add(contentP);}/// <summary>/// 添加段落/// </summary>/// <param name="content">内容</param>/// <param name="Alignment">对齐方式(1为居中,0为居左,2为居右)</param>/// <param name="SpacingAfter">段后空行数(0为默认值)</param>/// <param name="SpacingBefore">段前空行数(0为默认值)</param>/// <param name="MultipliedLeading">行间距(0为默认值)</param>public void AddParagraph(string content, int Alignment, float SpacingAfter, float SpacingBefore, float MultipliedLeading){Paragraph pra = new Paragraph(content, font);pra.Alignment = Alignment;if (SpacingAfter != 0){pra.SpacingAfter = SpacingAfter;}if (SpacingBefore != 0){pra.SpacingBefore = SpacingBefore;}if (MultipliedLeading != 0){pra.MultipliedLeading = MultipliedLeading;}document.Add(pra);}#endregion#region 添加图片/// <summary>/// 添加图片/// </summary>/// <param name="path">图片路径</param>/// <param name="Alignment">对齐方式(1为居中,0为居左,2为居右)</param>/// <param name="newWidth">图片宽(0为默认值,如果宽度大于页宽将按比率缩放)</param>/// <param name="newHeight">图片高</param>public Image AddImage(string imagePath, int Alignment, float newWidth, float newHeight){if (!File.Exists(imagePath)){Debug.Log("该路径下不存在指定图片,请检测路径是否正确!");return null;}Image img = Image.GetInstance(imagePath);img.Alignment = Alignment;if (newWidth != 0){img.ScaleAbsolute(newWidth, newHeight);}else{if (img.Width > PageSize.A4.Width){img.ScaleAbsolute(documentSize.Width, img.Width * img.Height / documentSize.Height);}}document.Add(img);return img;}/// <summary>/// 添加图片/// </summary>/// <param name="path">图片路径</param>/// <param name="Alignment">对齐方式(1为居中,0为居左,2为居右)</param>/// <param name="newWidth">图片宽</param>/// <param name="newHeight">图片高</param>public Image AddImage(string imagePath, int Alignment, int fitWidth, int fitHeight){if (!File.Exists(imagePath)){Debug.Log("该路径下不存在指定图片,请检测路径是否正确!");return null;}Image image = Image.GetInstance(imagePath);image.ScaleToFit(fitWidth, fitHeight);image.Alignment = Alignment;document.Add(image);return image;}#endregion #region Table表public void AddTable(PdfPTable table){document.Add(table);}#endregion}
}
using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using Font = iTextSharp.text.Font;
using Image = iTextSharp.text.Image;namespace PDFExport
{public class ReportExporterPDF: MonoBehaviour{private string fontPath = Application.streamingAssetsPath + "/Fonts/SIMFANG.TTF";string imagePath1 = Application.streamingAssetsPath + "/Images/logo.png";private void Start(){GenerateReportPDF();}public  void GenerateReportPDF(){CreatePDF(Application.streamingAssetsPath + "/Report.pdf");}private void CreatePDF(string filePath){using (FileStream fileStream = new FileStream(filePath, FileMode.Create)){PDFOperation pdf = new PDFOperation(PageSize.A4, 55f, 55f, 96f, 96f);pdf.SetBaseFont(fontPath);PdfWriter pdfWriter = pdf.OpenPdfWriter(fileStream);pdf.Open();HeaderFooterPageEvent headerFooterPageEvent = new HeaderFooterPageEvent(pdf,this);pdfWriter.PageEvent = headerFooterPageEvent;FirstPasge(pdf);pdf.Close();pdf.ClosePdfWriter();
#if UNITY_EDITORAssetDatabase.Refresh();
#endif}Application.OpenURL(filePath);}#region FirstPageprivate void FirstPasge(PDFOperation pdf){pdf.AddNullLine(1, 22);Image image1 = Image.GetInstance(imagePath1);PdfPTable table = new PdfPTable(1);table.DefaultCell.Border = Rectangle.NO_BORDER;table.DefaultCell.Padding = 0;table.DefaultCell.FixedHeight = 100;// 设置图片的缩放比例float scale = 0.9f;image1.ScaleAbsolute(image1.Width * scale, image1.Height * scale);PdfPCell cell1 = new PdfPCell(image1);cell1.HorizontalAlignment = 1;cell1.PaddingRight = 0;cell1.Border = Rectangle.NO_BORDER;table.AddCell(cell1);pdf.AddTable(table);pdf.AddNullLine();pdf.SetFont(24);pdf.AddParagraph("汽车实验系统", 1);pdf.AddNullLine();pdf.SetFont(36, Font.BOLD);pdf.AddParagraph("实验报告", 1);pdf.AddNullLine(3);AddMainInfo(pdf);}public void AddMainInfo(PDFOperation pdf){// 创建一个有 2 列的表格float[] columnWidths = { 124, 369 };PdfPTable table = new PdfPTable(columnWidths);table.DefaultCell.Border = Rectangle.NO_BORDER;// 设置表格宽度和对齐方式table.WidthPercentage = 80;table.HorizontalAlignment = Element.ALIGN_CENTER;string[] cellContents = {"实验名称:", "汽车仿真实验","实验地点:", "","学生姓名:", "","指导教师:", "","所属单位:", "","支持单位:", "XXXX科技大学","支持单位:", "XXXXXX股份有限公司","实验时间:", DateTime.Now.ToString("yyyy年MM月dd日")};// 用提供的信息添加表格单元格for (int i = 0; i < cellContents.Length; i++){PdfPCell cell;if (i % 2 == 0){pdf.SetFont(14, Font.BOLD);cell = new PdfPCell(new Phrase(cellContents[i], pdf.GetFont()));}else{pdf.SetFont(14, Font.NORMAL);cell = new PdfPCell(new Phrase(cellContents[i], pdf.GetFont()));}cell.Padding = 10;cell.Border = Rectangle.NO_BORDER;table.AddCell(cell);}pdf.AddTable(table);}#endregion#region  页眉页脚public class HeaderFooterPageEvent : PdfPageEventHelper{PDFOperation pdf;ReportExporterPDF reportExporter;public HeaderFooterPageEvent(PDFOperation pdf, ReportExporterPDF reportExporter){this.pdf = pdf;this.reportExporter = reportExporter;}public override void OnEndPage(PdfWriter writer, Document doc){base.OnEndPage(writer, doc);Header(writer, doc);Footer(writer, doc);}private void Header(PdfWriter writer, Document doc){float[] columnWidths = { 25, 200 };// 添加带图片和文字的页眉PdfPTable headerTable = new PdfPTable(columnWidths);headerTable.DefaultCell.Border = Rectangle.NO_BORDER;headerTable.WidthPercentage = 100;headerTable.HorizontalAlignment = Element.ALIGN_CENTER;headerTable.TotalWidth = doc.PageSize.Width - doc.LeftMargin - doc.RightMargin; // Set table widthheaderTable.LockedWidth = true; // Lock the table widthImage image1 = Image.GetInstance(reportExporter.imagePath1);// Add images to the headerimage1.ScaleAbsolute(image1.Width / 2, image1.Height / 2);PdfPCell imageCell1 = new PdfPCell(image1);imageCell1.Border = Rectangle.NO_BORDER;// Add text to the headerpdf.SetFont(10, Font.NORMAL, BaseColor.GRAY);Font headerFont = pdf.GetFont();PdfPCell textCell = new PdfPCell(new Phrase("XXXXXX股份有限公司", headerFont));textCell.HorizontalAlignment = Element.ALIGN_RIGHT;textCell.VerticalAlignment = Element.ALIGN_BOTTOM;textCell.Border = Rectangle.NO_BORDER;headerTable.AddCell(imageCell1);headerTable.AddCell(textCell);headerTable.WriteSelectedRows(0, -1, doc.Left, doc.Top + 60, writer.DirectContent);}private void Footer(PdfWriter writer, Document doc){// Add footer with page numberPdfPTable footerTable = new PdfPTable(1);footerTable.DefaultCell.Border = Rectangle.NO_BORDER;footerTable.WidthPercentage = 100;footerTable.HorizontalAlignment = Element.ALIGN_CENTER;footerTable.TotalWidth = doc.PageSize.Width - doc.LeftMargin - doc.RightMargin; // Set table widthfooterTable.LockedWidth = true; // Lock the table widthint pageNumber = writer.PageNumber;int totalPages = writer.CurrentPageNumber; // Exclude the cover pagepdf.SetFont(9, Font.NORMAL, BaseColor.GRAY);Font footFont = pdf.GetFont();PdfPCell footerCell = new PdfPCell(new Phrase($"{totalPages}", footFont));footerCell.HorizontalAlignment = Element.ALIGN_CENTER;footerCell.Border = Rectangle.NO_BORDER;footerTable.AddCell(footerCell);footerTable.WriteSelectedRows(0, -1, doc.Left, doc.Bottom - 50, writer.DirectContent);}}#endregion}
}




TechX —— 心探索、心进取!

每一次跌倒都是一次成长

每一次努力都是一次进步

END
感谢您阅读本篇博客!希望这篇内容对您有所帮助。如果您有任何问题或意见,或者想要了解更多关于本主题的信息,欢迎在评论区留言与我交流。我会非常乐意与大家讨论和分享更多有趣的内容。
如果您喜欢本博客,请点赞和分享给更多的朋友,让更多人受益。同时,您也可以关注我的博客,以便及时获取最新的更新和文章。
在未来的写作中,我将继续努力,分享更多有趣、实用的内容。再次感谢大家的支持和鼓励,期待与您在下一篇博客再见!

相关文章:

Unity之创建与导出PDF

内容将会持续更新&#xff0c;有错误的地方欢迎指正&#xff0c;谢谢! Unity之创建与导出PDF TechX 坚持将创新的科技带给世界&#xff01; 拥有更好的学习体验 —— 不断努力&#xff0c;不断进步&#xff0c;不断探索 TechX —— 心探索、心进取&#xff01; 助力快速…...

【Android面试八股文】优化View层次过深问题,选择哪个布局比较好?

优化深层次View层次结构的问题&#xff0c;选择合适的布局方式是至关重要的。以下是几点建议&#xff1a; 使用ConstraintLayout&#xff1a;ConstraintLayout是Android开发中推荐的布局&#xff0c;能够有效减少嵌套&#xff0c;提高布局性能。相比RelativeLayout&#xff0c;…...

什么是带有 API 网关的代理?

带有 API 网关的代理服务显著提升了用户体验和性能。特别是对于那些使用需要频繁创建和轮换代理的工具的用户来说&#xff0c;使用 API 可以节省大量时间并提高效率。 了解 API API&#xff0c;即应用程序编程接口&#xff0c;是服务提供商和用户之间的连接网关。通过 API 连接…...

sql拉链表

1、定义&#xff1a;维护历史状态以及最新数据的一种表 2、使用场景 1、有一些表的数据量很大&#xff0c;比如一张用户表&#xff0c;大约1亿条记录&#xff0c;50个字段&#xff0c;这种表 2.表中的部分字段会被update更新操作&#xff0c;如用户联系方式&#xff0c;产品的…...

STM32CubeMX实现矩阵按键(HAL库实现)

功能描述&#xff1a; 实现矩阵按键验证&#xff0c;将矩阵按键的按键值&#xff0c;通过串口显示&#xff0c;便于后面使用。 实物图 原理图&#xff1a; 编程原理&#xff1a; 原理很简单&#xff0c;就是通过循环设置引脚为低电平&#xff0c;另外引脚扫描读取电平值&…...

mmdetection3D指定版本安装指南

1. 下载指定版本号 选择指定版本号下载mmdetection3d的源码&#xff0c;如这里选择的是0.17.2版本 git clone https://github.com/open-mmlab/mmdetection3d.git -b v0.17.22. 安装 cd mmdetection3d安装依赖库 pip install -r requirment.txt编译安装 pip install -v e .…...

SQLMap工具详解与SQL注入防范

SQLMap工具详解与SQL注入防范 大家好&#xff0c;我是微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天我们将深入探讨SQLMap工具的详细使用方法以及如何防范SQL注入攻击。 SQL注入简介 SQL注入是一种常见的安全漏洞&am…...

如何在Java中实现自定义数据结构:从头开始

如何在Java中实现自定义数据结构&#xff1a;从头开始 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01;今天我们将探讨如何在Java中实现自定义数据结构&#xff…...

【机器学习】在【Pycharm】中的应用:【线性回归模型】进行【房价预测】

专栏&#xff1a;机器学习笔记 pycharm专业版免费激活教程见资源&#xff0c;私信我给你发 python相关库的安装&#xff1a;pandas,numpy,matplotlib&#xff0c;statsmodels 1. 引言 线性回归&#xff08;Linear Regression&#xff09;是一种常见的统计方法和机器学习算法&a…...

如何在 Linux 中后台运行进程?

一、后台进程 在后台运行进程是 Linux 系统中的常见要求。在后台运行进程允许您在进程独立运行时继续使用终端或执行其他命令。这对于长时间运行的任务或当您想要同时执行多个命令时特别有用。 在深入研究各种方法之前&#xff0c;让我们先了解一下什么是后台进程。在 Linux 中…...

软考-软件设计师

软考 软考科目 软考分为初级、中级、高级&#xff0c;初级含金量相对不够&#xff0c;高级考试有难度&#xff0c;所以大多数人都在考中级&#xff0c;中级也分很多科目&#xff0c;我考的是软件设计师&#xff08;已经通过&#xff09;。 合格标准 考试分为上午题和下午题…...

UOS系统中JavaFx笔锋功能

关于笔锋功能&#xff0c;网上找了很久&#xff0c;包括Java平台客户端&#xff0c;Android端&#xff0c;相关代码资料比较少&#xff0c;找了很多经过测试效果都差强人意&#xff0c;自己也搓不出来&#xff0c;在UOS平台上JavaFX也获取不到压力值&#xff0c;只能用速度的变…...

后端加前端Echarts画图示例全流程(折线图,饼图,柱状图)

本文将带领读者通过一个完整的Echarts画图示例项目&#xff0c;演示如何结合后端技术&#xff08;使用Spring Boot框架&#xff09;和前端技术&#xff08;使用Vue.js或React框架&#xff09;来实现数据可视化。我们将实现折线图、饼图和柱状图三种常见的数据展示方式&#xff…...

ValidateAntiForgeryToken、AntiForgeryToken 防止CSRF(跨网站请求伪造)

用途&#xff1a;防止CSRF&#xff08;跨网站请求伪造&#xff09;。 用法&#xff1a;在View->Form表单中: aspx&#xff1a;<%:Html.AntiForgeryToken()%> razor&#xff1a;Html.AntiForgeryToken() 在Controller->Action动作上&#xff1a;[ValidateAntiForge…...

《昇思25天学习打卡营第5天 | mindspore 网络构建 Cell 常见用法》

1. 背景&#xff1a; 使用 mindspore 学习神经网络&#xff0c;打卡第五天&#xff1b; 2. 训练的内容&#xff1a; 使用 mindspore 的 nn.Cell 构建常见的网络使用方法&#xff1b; 3. 常见的用法小节&#xff1a; 支持一系列常用的 nn 的操作 3.1 nn.Cell 网络构建&…...

SQLServer:从数据类型 varchar 转换为 numeric 时出错。

1.工作要求 计算某两个经纬度距离 2.遇到问题 从数据类型 varchar 转换为 numeric 时出错。 3.解决问题 项目版本较老&#xff0c;使用SQLServer 2012 计算距离需执行视图&#xff0c;如下&#xff1a; SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON GO ALTER view vi_ord…...

探索迁移学习:通过实例深入理解机器学习的强大方法

探索迁移学习&#xff1a;通过实例深入理解机器学习的强大方法 &#x1f341;1. 迁移学习的概念&#x1f341;2. 迁移学习的应用领域&#x1f341;2.1 计算机视觉&#x1f341;2.2 自然语言处理&#xff08;NLP&#xff09;&#x1f341;2.3 医学图像分析&#x1f341;2.4 语音…...

【Linux】性能分析器 perf 详解(四):trace

上一篇:【Linux】性能分析器 perf 详解(三) 1、trace 1.1 简介 perf trace 类似于 strace 工具:用于对Linux系统性能分析和调试的工具。 原理是:基于 Linux 性能计数器(Performance Counters for Linux, PCL),监控和记录系统调用和其他系统事件。 可以提供关于硬件…...

信息安全体系架构设计

对信息系统的安全需求是任何单一安全技术都无法解决的&#xff0c;要设计一个信息安全体系架构&#xff0c;应当选择合适的安全体系结构模型。信息系统安全设计重点考虑两个方面&#xff1b;其一是系统安全保障体系&#xff1b;其二是信息安全体系架构。 1.系统安全保障体系 安…...

GPT-5即将登场:AI赋能下的未来工作与日常生活新图景

随着OpenAI首席技术官米拉穆拉蒂在近期采访中的明确表态&#xff0c;GPT-5的发布已不再是遥不可及的梦想&#xff0c;而是即将在一年半后与我们见面的现实。这一消息无疑在科技界乃至全社会引发了广泛关注和热烈讨论。从GPT-4到GPT-5的飞跃&#xff0c;被形容为从高中生到博士生…...

树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法

树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源&#xff1a; http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作&#xff0c;无需更改相机配置。但是&#xff0c;一…...

Frozen-Flask :将 Flask 应用“冻结”为静态文件

Frozen-Flask 是一个用于将 Flask 应用“冻结”为静态文件的 Python 扩展。它的核心用途是&#xff1a;将一个 Flask Web 应用生成成纯静态 HTML 文件&#xff0c;从而可以部署到静态网站托管服务上&#xff0c;如 GitHub Pages、Netlify 或任何支持静态文件的网站服务器。 &am…...

uniapp中使用aixos 报错

问题&#xff1a; 在uniapp中使用aixos&#xff0c;运行后报如下错误&#xff1a; AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...

大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计

随着大语言模型&#xff08;LLM&#xff09;参数规模的增长&#xff0c;推理阶段的内存占用和计算复杂度成为核心挑战。传统注意力机制的计算复杂度随序列长度呈二次方增长&#xff0c;而KV缓存的内存消耗可能高达数十GB&#xff08;例如Llama2-7B处理100K token时需50GB内存&a…...

return this;返回的是谁

一个审批系统的示例来演示责任链模式的实现。假设公司需要处理不同金额的采购申请&#xff0c;不同级别的经理有不同的审批权限&#xff1a; // 抽象处理者&#xff1a;审批者 abstract class Approver {protected Approver successor; // 下一个处理者// 设置下一个处理者pub…...

作为测试我们应该关注redis哪些方面

1、功能测试 数据结构操作&#xff1a;验证字符串、列表、哈希、集合和有序的基本操作是否正确 持久化&#xff1a;测试aof和aof持久化机制&#xff0c;确保数据在开启后正确恢复。 事务&#xff1a;检查事务的原子性和回滚机制。 发布订阅&#xff1a;确保消息正确传递。 2、性…...

【堆垛策略】设计方法

堆垛策略的设计是积木堆叠系统的核心&#xff0c;直接影响堆叠的稳定性、效率和容错能力。以下是分层次的堆垛策略设计方法&#xff0c;涵盖基础规则、优化算法和容错机制&#xff1a; 1. 基础堆垛规则 (1) 物理稳定性优先 重心原则&#xff1a; 大尺寸/重量积木在下&#xf…...

如何配置一个sql server使得其它用户可以通过excel odbc获取数据

要让其他用户通过 Excel 使用 ODBC 连接到 SQL Server 获取数据&#xff0c;你需要完成以下配置步骤&#xff1a; ✅ 一、在 SQL Server 端配置&#xff08;服务器设置&#xff09; 1. 启用 TCP/IP 协议 打开 “SQL Server 配置管理器”。导航到&#xff1a;SQL Server 网络配…...

前端开发者常用网站

Can I use网站&#xff1a;一个查询网页技术兼容性的网站 一个查询网页技术兼容性的网站Can I use&#xff1a;Can I use... Support tables for HTML5, CSS3, etc (查询浏览器对HTML5的支持情况) 权威网站&#xff1a;MDN JavaScript权威网站&#xff1a;JavaScript | MDN...

Python常用模块:time、os、shutil与flask初探

一、Flask初探 & PyCharm终端配置 目的: 快速搭建小型Web服务器以提供数据。 工具: 第三方Web框架 Flask (需 pip install flask 安装)。 安装 Flask: 建议: 使用 PyCharm 内置的 Terminal (模拟命令行) 进行安装,避免频繁切换。 PyCharm Terminal 配置建议: 打开 Py…...