CultivationOfBrewing/Assets/Scripts/Test/LoadPPTTest.cs

49 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Aspose.Slides;
using Aspose.Words.Lists;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class LoadPPTTest
{
public static List<Texture2D> LoadPPTGO(string pptPath)
{
List<Texture2D> textures = new List<Texture2D>();
Presentation presentation = new Aspose.Slides.Presentation(pptPath);
//遍历文档(只做示例使用自己根据需求拓展)
for (int i = 0; i < presentation.Slides.Count; i++)
{
ISlide slide = presentation.Slides[i];
var bitmap = slide.GetThumbnail(1f, 1f);
//声明内存流将图片转换为内存流再由流转换为byte数组然后用texture2d加载byte数组
using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, ImageFormat.Jpeg);
byte[] buff = new byte[ms.Length];
ms.Seek(0, SeekOrigin.Begin);
ms.Read(buff, 0, (int)ms.Length);
//注意这个iamge的命名空间为system.drawing不是unity.ui,这个图片的目的是提供图片的宽高
System.Drawing.Image sizeImage = System.Drawing.Image.FromStream(ms);
Texture2D texture2D = new Texture2D(sizeImage.Width, sizeImage.Height);
texture2D.LoadImage(buff);
textures.Add(texture2D);
//用texture2d为精灵赋值
}
}
return textures;
}
public static void GetThingsByName()
{
}
}