TGALoader.LoadTGA C# (CSharp) Метод

LoadTGA() публичный статический Метод

public static LoadTGA ( Stream TGAStream ) : Texture2D
TGAStream Stream
Результат UnityEngine.Texture2D
    public static Texture2D LoadTGA(Stream TGAStream)
    {
        using (BinaryReader r = new BinaryReader(TGAStream))
        {
            // Skip some header info we don't care about.
            // Even if we did care, we have to move the stream seek point to the beginning,
            // as the previous method in the workflow left it at the end.
            r.BaseStream.Seek(12, SeekOrigin.Begin);

            short width = r.ReadInt16();
            short height = r.ReadInt16();
            int bitDepth = r.ReadByte();

            // Skip a byte of header information we don't care about.
            r.BaseStream.Seek(1, SeekOrigin.Current);

            Texture2D tex = new Texture2D(width, height);
            Color32[] pulledColors = new Color32[width * height];

            if (bitDepth == 32)
            {
                for (int i = 0; i < width * height; i++)
                {
                    byte red = r.ReadByte();
                    byte green = r.ReadByte();
                    byte blue = r.ReadByte();
                    byte alpha = r.ReadByte();

                    pulledColors [i] = new Color32(blue, green, red, alpha);
                }
            } else if (bitDepth == 24)
            {
                for (int i = 0; i < width * height; i++)
                {
                    byte red = r.ReadByte();
                    byte green = r.ReadByte();
                    byte blue = r.ReadByte();

                    pulledColors [i] = new Color32(blue, green, red, 1);
                }
            } else
            {
                throw new Exception("TGA texture had non 32/24 bit depth.");
            }

            tex.SetPixels32(pulledColors);
            tex.Apply();
            return tex;
        }
    }

Same methods

TGALoader::LoadTGA ( string fileName ) : Texture2D

Usage Example

Пример #1
0
    public override Texture2D LoadImageAt(int index, bool Alpha)
    {
        switch (_RES)
        {
        case GAME_UW2:
        {
            return(extractUW2Bitmap("data\\byt.ark", index, Alpha));
        }

        default:
        {
            if (File.Exists(BasePath + FilePaths[index].Replace(".", "_") + "\\001.tga"))
            {
                return(TGALoader.LoadTGA(BasePath + FilePaths[index].Replace(".", "_") + "\\001.tga"));
            }
            if (currentIndex != index)
            {                    //Only load from disk if the image to bring back has changed.
                DataLoaded = false;
                Path       = FilePaths[index];
                LoadImageFile();
            }
            return(Image(ImageFileData, 0, 320, 200, "name_goes_here", GameWorldController.instance.palLoader.Palettes[PaletteIndices[index]], Alpha));
        }
        }
    }
All Usage Examples Of TGALoader::LoadTGA
TGALoader