c# - 复制 Texture2D 以保持原始不变
问题描述
如何在 Unity 中正确复制 Texture2D,我尝试Graphics.CopyTexture(texture, copy);
让它告诉我这两个图像不兼容,我如何解决这个问题并获得图像的完美副本,我查找的所有内容都与关于如何裁剪复制的图像或使用 RenderTextures 时,但我找不到有关如何创建大小和像素颜色相同的 Texture2D 副本的任何信息。
解决方案
尝试使用Texture2D 类的构造函数以及方法SetPixels和Apply。
Texture2D copyTexture = new Texture2D(originalTexture.width, originalTexture.height);
copyTexture.SetPixels(originalTexture.GetPixels());
copyTexture.Apply();
您可能会遇到错误:
UnityException: Texture 'YourTexture' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
正如它所说。您可以通过单击项目选项卡中的纹理以在检查器中打开导入设置并选中Read/Write Enabled
复选框来解决它。
推荐阅读
- sox - SoX 中的noiseprof 是否获得声音的平均测量值?
- spring-integration - 如何在应用程序上下文 xml 中添加错误通道以收集和分散?
- python - 如何使用 Pytorch 将增强图像添加到原始数据集中?
- c - 乘法字符串
- openlayers - OpenLayers v 5.3.0:地图导出
- c# - 如何保存和打开 xaml 文件?
- java - Thymeleaf 多对多复选框列表
- php - 将 wordpress 网站移动到另一个域后显示索引文件的代码
- python - 根据 Spacy 中的索引返回单词
- python - flask-cors 未发送预检 CORS 请求