ThemeEditor.Common.Graphics.RawTexture.Decode C# (CSharp) Method

Decode() public method

public Decode ( ) : byte[]
return byte[]
        public byte[] Decode()
        {
            switch (Format)
            {
                case DataFormat.Bgr565:
                    return Decode_Bgr565();
                case DataFormat.Bgr888:
                    return Decode_Bgr888();
                case DataFormat.A8:
                    return Decode_A8();
            }
            return null;
        }

Usage Example

 private BitmapSource DecodeTexture(RawTexture model)
 {
     BitmapSource bmp;
     switch (model.Format)
     {
         default:
         case RawTexture.DataFormat.Invalid:
         {
             return null;
         }
         case RawTexture.DataFormat.Bgr888:
         case RawTexture.DataFormat.Bgr565:
         {
             var rgb888 = model.Decode();
             bmp = BitmapSource.Create(model.Width,
                 model.Height,
                 96,
                 96,
                 PixelFormats.Bgr24,
                 null,
                 rgb888,
                 model.Width * 3);
             break;
         }
         case RawTexture.DataFormat.A8:
         {
             var rgb888 = model.Decode();
             var alpha = GscToAlpha(rgb888);
             bmp = BitmapSource.Create(model.Width,
                 model.Height,
                 96,
                 96,
                 PixelFormats.Bgra32,
                 null,
                 alpha,
                 model.Width * 4);
             break;
         }
     }
     bmp.Freeze();
     return bmp;
 }