示例#1
0
        public static Texture2D LoadTexture(byte[] bytes)
        {
            Texture2D result;

            using (var memoryStream = new MemoryStream(bytes))
            {
                long num = 0L;
                PngAssist.CheckPngData(memoryStream, ref num, false);
                if (num == 0L)
                {
                    result = null;
                }
                else
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                    {
                        byte[] data = binaryReader.ReadBytes((int)num);
                        int    num2 = 0;
                        int    num3 = 0;
                        result = PngAssist.ChangeTextureFromPngByte(data, ref num2, ref num3);
                    }
                }
            }
            return(result);
        }
示例#2
0
 public static Texture2D LoadTexture(string _path)
 {
     using (FileStream fileStream = new FileStream(_path, FileMode.Open, FileAccess.Read))
     {
         long pngSize = PngFile.GetPngSize((Stream)fileStream);
         if (pngSize == 0L)
         {
             return((Texture2D)null);
         }
         using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
         {
             byte[] data   = binaryReader.ReadBytes((int)pngSize);
             int    width  = 0;
             int    height = 0;
             return(PngAssist.ChangeTextureFromPngByte(data, ref width, ref height, (TextureFormat)5, false));
         }
     }
 }
示例#3
0
 public static Sprite LoadSpriteFromFile(string path)
 {
     using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         long pngSize = PngFile.GetPngSize((Stream)fileStream);
         if (pngSize == 0L)
         {
             return((Sprite)null);
         }
         using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
         {
             byte[]    data      = binaryReader.ReadBytes((int)pngSize);
             int       width     = 0;
             int       height    = 0;
             Texture2D texture2D = PngAssist.ChangeTextureFromPngByte(data, ref width, ref height, (TextureFormat)5, false);
             return(Object.op_Equality((Object)null, (Object)texture2D) ? (Sprite)null : Sprite.Create(texture2D, new Rect(0.0f, 0.0f, (float)width, (float)height), new Vector2(0.5f, 0.5f)));
         }
     }
 }
示例#4
0
        public static Texture2D LoadTexture(byte[] bytes)
        {
            Texture2D result = null;

            using (MemoryStream memStream = new MemoryStream(bytes))
            {
                long pngSize = PngFile.GetPngSize(memStream);
                if (pngSize != 0L)
                {
                    using (BinaryReader binaryReader = new BinaryReader(memStream))
                    {
                        byte[] data = binaryReader.ReadBytes((int)pngSize);
                        int    width = 0, height = 0;
                        result = PngAssist.ChangeTextureFromPngByte(data, ref width, ref height);
                    }
                }
            }

            return(result);
        }