Unity 读取及设置图片坐标像素

您所在的位置:网站首页 像素1×1透明图片 Unity 读取及设置图片坐标像素

Unity 读取及设置图片坐标像素

2023-03-20 01:22| 来源: 网络整理| 查看: 265

注意: 代码还有些许问题,第二次运行的时候才能成功,程序运行之后,图片透明度不还原,仅供参考

1.测试图片

修改图片属性:

2.Texture2DOP.cs

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Texture2DOP : MonoBehaviour { Texture2D texture; Color color; void Start () { color = new Color(0, 0, 0, 0f); texture = new Texture2D(GetComponent().texture.width, GetComponent().texture.height, TextureFormat.BGRA32, false); texture = GetComponent().texture as Texture2D; texture.Apply(); for (int y = 0; y < texture.height/2; y++) { for (int x = 0; x < texture.width; x++) { if (texture.GetPixel(x, y).r == 0 && texture.GetPixel(x, y).g == 0 && texture.GetPixel(x, y).b == 0) { texture.SetPixel(x, y + texture.height / 2, color); } } } } }

3.未运行前

运行后 :(运行没反应,再运行一次)

下半部分图片坐标像素如果是黑色,则将上半部分对应的像素设置成透明



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3