Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

EncodeToPNG and ARGB32: not getting any alpha channel?

Discussion in 'Scripting' started by michael_polak, Aug 20, 2009.

  1. michael_polak

    michael_polak

    Joined:
    Aug 20, 2009
    Posts:
    24
    Hi all,
    I'm performing a screen capture and then saving the data as a .png file. When I open the .png in Photoshop I only see the RGB channels even though the source was an ARGB32 texture. Here is the C# code:

    Code (csharp):
    1. tex = new Texture2D(mainWidth, mainHeight, TextureFormat.ARGB32, false);
    2. tex.ReadPixels(new Rect(0, 0, mainWidth, mainHeight), 0, 0, false);
    3.                        
    4. byte[] png = tex.EncodeToPNG();
    5. File.WriteAllBytes(ShotFName1, png);
    6.  
    Before taking the shot I disable the background texture. I have set the camera background color to be RGBA = 0,0,0,0. My pictures have a black background but no alpha. What else do I need to do to get a transparent PNG?

    Thanks,
    Michael
     
  2. michael_polak

    michael_polak

    Joined:
    Aug 20, 2009
    Posts:
    24
    I got the transparency working without changing the code that was displayed. I must have lost an alpha setting change on my background color.

    The thumbnail now has transparency except one of my materials seems to be translucent in the image. I have a couple of meshes that make a person - head, hair, eyes, and a shirt. For some reason the blue shirt appears white with a blue tint in the PNG. The shader is 'bumped specular' and the material has a blue texture. I'm not sure where the transparency on the shirt is coming from. Ideas anyone? I'll post this issue in a new thread as well.