简体   繁体   English

PDF转换为Texture2D数组?

[英]PDF to Texture2D array?

        //add icon
        byte[] fileBytes;
        Texture2D tex = null;

        if (File.Exists(*path to file*))
        {
            fileData = File.ReadAllBytes(*path to file*);
            tex = new Texture2D(2, 2);
            tex.LoadImage(fileBytes); 
        }

        //Read Texture into RawImage component
        GameObject.GetComponent<RawImage>().material.mainTexture = tex;

The above code can dynamically create and display images (jpeg, jpg, png) in Unity. 上面的代码可以在Unity中动态创建和显示图像(jpeg,jpg,png)。 I'm seeking to do the same for a PDF. 我正在寻求对PDF进行同样的操作。

As far as I've seen through my research, there are PDF renderers available on the asset store however, they are expensive. 据我的研究显示,资产商店中有可用的PDF渲染器,但是它们很昂贵。 Unfortunately there aren't any low grade or free options that load PDFs. 不幸的是,没有任何低级或免费的选项可以加载PDF。

When I try to run my code on PDFs, it returns what looks like a factory image of a red question mark icon on a blank white background. 当我尝试在PDF上运行代码时,它返回的内容看起来像是空白白色背景上的红色问号图标的出厂图像。

My code isn't reading the PDF into an array, creating an image/texture for each page. 我的代码不是将PDF读入数组,而是为每页创建图像/纹理。 Before I dive head first and do this, I'm reaching out to you. 在我开始潜水之前,请先与您联系。 Is this plausible? 这看似合理吗? Are there better options? 有更好的选择吗? Am I SOL and my time would be better spent buying a pre-made asset? 我是SOL,我的时间会花在购买预制资产上吗?

Instead of working with the PDF directly it may be easier to convert to an image file, and use your code to convert the new image to the Texture2D array. 与其直接使用PDF,不如直接转换为图像文件,并使用您的代码将新图像转换为Texture2D数组可能更容易。 I have not personally done this but this SO question seems to outline it pretty well: 我个人没有这样做,但是这个SO问题似乎很好地概述了它:

Save pdf to jpeg using c# 使用C#将pdf保存为jpeg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM