unity3d - Unity如何将相同颜色的所有像素更改为另一种颜色?
问题描述
例如,我有一个 png 文件,我想将 png 文件中具有相同 RGB 值的所有像素转换为另一种颜色。我正在制作一个包含省份的交互式地图,我想要一个文件,其中所有省份都有不同的 RGB 值,并使用省份颜色作为 id 系统。问题是我不知道如何将 RGB 值更改为另一个
解决方案
如果它是 Texture2D,您可以按如下方式更改像素:
Texture2D texture = new Texture2D(128, 128); // load your texture here
Color colortrigger = Color.Blue; // color triggers to change
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
if(texture.GetPixel(x,y) == colortrigger)
{
// Change the pixel to another color
texture.SetPixel(x, y, Color.Yellow);
}
}
}
texture.Apply();
推荐阅读
- google-cloud-platform - 将 TPU 与 PyTorch 一起使用
- scala - Gradle 错误:路径为“无法在根项目”中找到的项目
- javascript - Here Maps api:如何在地图上显示当前中心(JavaScript)
- spring-boot - 如何从授权码 OAuth2 中获取电子邮件地址
- javascript - 如何正确“toDate()”Firestore 时间戳的大型文档?
- git - Azure DevOps - 组合项目的克隆命令是什么?
- c++ - 在运行时为动态分配的内存输入值
- mysql - 将日期拆分为多列
- python-2.7 - 基于列位置的Python合并
- c# - 将字典中的键复制到另一个字典