当前位置:网站首页>Unity 加载读取PPT
Unity 加载读取PPT
2022-07-30 23:18:00 【柏雁】
效果

问题
本例子结合FancyScrollView,读取PPT效果。PPT读取的时候有点卡顿,建议优化一下,在程序启动前预加载一下PPT,缓存在内存里,体感会更好。
说明
Unity版本:2021.3.6f1c1
Unity API兼容等级:Net Framework4.x

DLL库:
Aspose.Slides:下载 .NET DLL 以读取编辑演示文稿|Aspose.Slides
https://releases.aspose.com/slides/net/
System.Drawing:2021.3.6f1c1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit中找
两个库我已经给大家封装在一个包里了,大家下载即可。
包名:PPT_FancyScrollView.unitypackage
链接:https://pan.baidu.com/s/1KAhXOgSty8yI-G_LkrnXhQ
提取码:n335
// 核心代码
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using UnityEngine;
using System.Threading.Tasks;
using Aspose.Slides;
namespace FancyScrollView.PPT
{
public class PPTDManager : MonoBehaviour
{
private static PPTDManager instance;
public static PPTDManager Instance
{
get
{
if (instance == null)
{
instance = new GameObject().AddComponent<PPTDManager>();
// instance = new PPTDManager();
}
return instance;
}
}
public Presentation LoadPPT(string path)
{
if (File.Exists(path) == false) return null;
return new Presentation(path);
}
private Dictionary<string, Sprite> itemDatasCash = new Dictionary<string, Sprite>();
public void LoadPPTByIndex(ItemData itemData, Action<Sprite> completion)
{
Sprite sprite;
var key = itemData.path + itemData.pageIndex;
if (itemDatasCash.TryGetValue(key, out sprite))
{
completion?.Invoke(sprite);
}
else
{
Presentation presentation = itemData.presentation;
int index = itemData.pageIndex;
var slide = presentation.Slides[index];
var bitmap = slide.GetThumbnail(1, 1);
Bitmap2Byte(bitmap, (bytes) =>
{
// PPT的尺寸
// int width = 960;
// int height = 540;
int width = Convert.ToInt16(presentation.SlideSize.Size.Width);
int height = Convert.ToUInt16(presentation.SlideSize.Size.Height);
Texture2D texture2D = new Texture2D(width, height);
texture2D.LoadImage(bytes);
sprite = Sprite.Create(texture2D, new Rect(0, 0, width, height), Vector2.zero);
if (itemDatasCash.ContainsKey(key) == false)
{
itemDatasCash.Add(key, sprite);
}
completion?.Invoke(sprite);
});
}
}
private async Task Bitmap2Byte(Bitmap bitmap, Action<byte[]> completion)
{
using (MemoryStream stream = new MemoryStream())
{
bitmap.Save(stream, ImageFormat.Png);
byte[] data = new byte[stream.Length];
stream.Seek(0, SeekOrigin.Begin);
await stream.ReadAsync(data, 0, Convert.ToInt32(stream.Length));
completion?.Invoke(data);
}
}
}
}如果本文章对你有所帮助,请让我看到你的赞好吗?
边栏推荐
- uniapp develops WeChat applet - soft exam brushing applet
- 2021GDCPC Guangdong University Student Programming Competition H.History
- 【LeetCode】64. 最小路径和 - Go 语言题解
- 实验8(vlan实验)
- 反转链表-头插反转法
- uniapp folding box secondary loop
- In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
- 2sk2225 Substitute 3A/1500V Chinese Documentation【PDF Data Book】
- Soft Exam Summary
- 智能创意中的尺寸拓展模块
猜你喜欢
随机推荐
“由于找不到MSVCP140.dll,无法继续执行代码,重新安装程序可能会解决此问题等”解决方案
proemthues 服务发现配置
智能创意中的尺寸拓展模块
IJCAI2022教程 | 口语语言理解:最新进展和新领域
[SAM template question] P3975 [TJOI2015] string theory
Data cleaning - ingest using es
Go1.18升级功能 - 泛型 从零开始Go语言
Successfully solved ImportError: always import the name '_validate_lengths'
"Wei cup" school more than 2022 cattle summer camp 4 L.B lack Hole, computational geometry
Apache Doris系列之:安装与部署详细步骤
uni-ui安装
如何在 AWS 中应用 DevOps 方法?
【云驻共创】HCSD大咖直播–就业指南
2022 Nioke Summer Multi-School Training Camp 1 J Serval and Essay
mysql 中手动设置事务提交
【飞控开发基础教程10】疯壳·开源编队无人机-PID 基础原理
reindex win10
编码与进制
PhpMetrics usage
【LeetCode】42. 接雨水 - Go 语言题解









