unity 多张图片合成一张图片

在工作中遇到了需要把两张图片合成一张图片的需求,在网上没有查找到好的解决方法,经过查找和询问别人解决了这个问题。话不多说上干货!

 public Texture2D TwoToOne(Texture2D source, Texture2D target)//图片合成
        {
    
     for (int x = 0; x < target.width; x++)
              {
    
      for (int y = 0; y < target.height; y++)
               if (target.GetPixel(x, y).a != 0)
                    {
    
    
                        source.SetPixel(x, y, new Color(target.GetPixel(x, y).r, target.GetPixel(x, y).g,
    target.GetPixel(x, y).b, target.GetPixel(x, y).a));
                    } 
                      }
            }
                      source.Apply();
                            return source;

这次干货分享就到这里 如果对你有所帮助请给我点个赞!

猜你喜欢

转载自blog.csdn.net/qq_43687127/article/details/107693664