https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
        public Texture2D CopyTexture(Texture2D texture)
        {
            // Create a temporary RenderTexture of the same size as the texture
            RenderTexture tmp = RenderTexture.GetTemporary(
                                texture.width,
                                texture.height,
                                0,
                                RenderTextureFormat.Default,
                                RenderTextureReadWrite.Linear);
 
            // Blit the pixels on texture to the RenderTexture
            Graphics.Blit(texture, tmp);
 
            // Backup the currently set RenderTexture
            RenderTexture previous = RenderTexture.active;
 
            // Set the current RenderTexture to the temporary one we created
            RenderTexture.active = tmp;
 
            // Create a new readable Texture2D to copy the pixels to it
            Texture2D myTexture2D = new Texture2D(texture.width, texture.height);
 
            // Copy the pixels from the RenderTexture to the new Texture
            myTexture2D.ReadPixels(new Rect(00, tmp.width, tmp.height), 00);
            myTexture2D.Apply();
 
            // Reset the active RenderTexture
            RenderTexture.active = previous;
 
            // Release the temporary RenderTexture
            RenderTexture.ReleaseTemporary(tmp);
 
            // "myTexture2D" now has the same pixels from "texture" and it's readable.
 
            return myTexture2D;
        }
cs


'Unity > Tip' 카테고리의 다른 글

단축키  (0) 2018.12.25
AssetDatabase.GetAssetBundleDependencies  (0) 2018.12.06

+ Recent posts