简体   繁体   English

是否可以对从项目外部在运行时加载的图像使用“ Alpha是透明度”设置?

[英]Can I use the Alpha is Transparency setting for an image loaded at runtime from outside the project?

I'm working on a system in my Unity project (2017.2.0f3) wherein a class will grab images from a specific folder outside of the project on the local system for use with a character skin. 我正在Unity项目(2017.2.0f3)中的系统上工作,其中一个类将从本地系统上项目外部的特定文件夹中抓取图像以与角色皮肤配合使用。 I need these textures to exist outside the project because I want to allow players to add additional content to the game post-build. 我需要这些纹理存在于项目外部,因为我想允许玩家向游戏后期构建添加其他内容。

My method for doing this is use of the WWW class, specifically by creating a Texture2D and loading an image into memory with WWW.LoadImageIntoTexture(). 我执行此操作的方法是使用WWW类,特别是通过创建Texture2D并使用WWW.LoadImageIntoTexture()将图像加载到内存中。 It is working just fine this way, no problems with that part. 这样就可以正常工作,而这部分没有问题。 When I display these images in the UI they look really bad. 当我在用户界面中显示这些图像时,它们看起来真的很糟糕。 If I manually add the same image to the project and check "Alpha is Transparency" they look just fine. 如果我手动将相同的图像添加到项目中并选中“ Alpha is Transparency”,它们看起来就很好。 I want to be able to apply that setting to the images as I load them into memory, but I can't figure out how. 我希望能够在将图像加载到内存中时将该设置应用于图像,但是我不知道该如何做。

I know that the setting dilates the color of the image, as is described here: https://docs.unity3d.com/Manual/TextureTypes.html 我知道该设置会扩大图像的颜色,如下所述: https : //docs.unity3d.com/Manual/TextureTypes.html

I'm wondering if it's possible to somehow do this on the fly programmatically. 我想知道是否有可能以编程方式即时进行此操作。 Has anyone tried this before? 有人尝试过吗? I'd imagine that the WWW class isn't the best method to be doing this with, but I can't find any info about other methods. 我以为WWW类不是执行此操作的最佳方法,但是我找不到有关其他方法的任何信息。

You can also use this method : http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.LoadImage.html 您也可以使用以下方法: http : //docs.unity3d.com/Documentation/ScriptReference/Texture2D.LoadImage.html

So you can at first create a texture in the format you would like and then using this method to load the image from a byte array. 因此,您可以首先以所需的格式创建纹理,然后使用此方法从字节数组加载图像。

You can get all the bytes of the file from System.IO.File.ReadAllBytes(filePath); 您可以从System.IO.File.ReadAllBytes(filePath);获得文件的所有字节。

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

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