zoukankan      html  css  js  c++  java
  • Texture to texture2D以及texture2D像素反转

        private void SaveRenderTextureToPNG(Texture inputTex, string file)
        {
            RenderTexture temp = RenderTexture.GetTemporary(inputTex.width, inputTex.height, 0, RenderTextureFormat.ARGB32);
            Graphics.Blit(inputTex, temp);
            Texture2D tex2D = GetRTPixels(temp);
            RenderTexture.ReleaseTemporary(temp);
            File.WriteAllBytes(file, tex2D.EncodeToPNG());
        }
    
        private Texture2D GetRTPixels(RenderTexture rt)
        {
            RenderTexture currentActiveRT = RenderTexture.active;
            RenderTexture.active = rt;
            Texture2D tex = new Texture2D(rt.width, rt.height);
            tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0);
            RenderTexture.active = currentActiveRT;
            return tex;
        }
                Color[] colors = tex.GetPixels(capx, capy, capwidth, capheight);
                System.Array.Reverse(colors, 0, colors.Length);
    
    
                Texture2D t = new Texture2D(capwidth, capheight, TextureFormat.RGB24, true);
                //Debug.Log("Pixel size:" + capx + " " + capy + " " + capwidth + " " + capheight);
                //t.ReadPixels(new Rect(capx, capy, capwidth, capheight), 0, 0, false);
    
                //for (int i = 0; i < capwidth; i++)
                //{
                //    for(int j=0;j<capheight;j++)
                //    {
                //        Color temp = t.GetPixel(i, j);
                //        t.SetPixel(i,j,)
                //    }
                //}
    
                t.SetPixels(colors);
                t.Apply();
  • 相关阅读:
    2019年春季第四周作业
    第三周作业
    第二周作业
    最大值及其下标
    查找整数
    PTA3
    币值转换
    三位老师
    自我介绍
    poj 3278 Catch That Cow(bfs)
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/8359013.html
Copyright © 2011-2022 走看看