Exemple #1
0
        public override ImageMetaData ReadMetaData(Stream stream)
        {
            stream.Seek(4, SeekOrigin.Current);
            int data_size = stream.ReadByte() | stream.ReadByte() << 8 | stream.ReadByte() << 16 | stream.ReadByte() << 24;

            stream.Seek(4, SeekOrigin.Current);
            using (var reader = new Reader(stream, 0x22))  // BMP header
            {
                reader.Unpack();
                var bmp = reader.Data;
                if (bmp[0] != 'B' || bmp[1] != 'M')
                {
                    return(null);
                }
                int width  = LittleEndian.ToInt32(bmp, 0x12);
                int height = LittleEndian.ToInt32(bmp, 0x16);
                int bpp    = LittleEndian.ToInt16(bmp, 0x1c);
                return(new GrdMetaData
                {
                    Width = (uint)width,
                    Height = (uint)height,
                    BPP = bpp,
                    DataSize = data_size,
                });
            }
        }
Exemple #2
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (GrdMetaData)info;

            stream.Position = 12;
            using (var reader = new Reader(stream.AsStream, meta.DataSize))
            {
                reader.Unpack();
                byte[] pixels = reader.Data;
                using (var bmp = new MemoryStream(reader.Data))
                {
                    var decoder = new BmpBitmapDecoder(bmp,
                                                       BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    BitmapSource frame = decoder.Frames[0];
                    frame.Freeze();
                    return(new ImageData(frame, info));
                }
            }
        }
Exemple #3
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as GrdMetaData;
            if (null == meta)
                throw new ArgumentException ("GrdFormat.Read should be supplied with GrdMetaData", "info");

            stream.Position = 12;
            using (var reader = new Reader (stream, meta.DataSize))
            {
                reader.Unpack();
                byte[] pixels = reader.Data;
                using (var bmp = new MemoryStream (reader.Data, false))
                {
                    var decoder = new BmpBitmapDecoder (bmp,
                        BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    BitmapSource frame = decoder.Frames[0];
                    frame.Freeze();
                    return new ImageData (frame, info);
                }
            }
        }
Exemple #4
0
        public override ImageData Read(Stream stream, ImageMetaData info)
        {
            var meta = info as GrdMetaData;

            if (null == meta)
            {
                throw new ArgumentException("GrdFormat.Read should be supplied with GrdMetaData", "info");
            }

            stream.Position = 12;
            using (var reader = new Reader(stream, meta.DataSize))
            {
                reader.Unpack();
                byte[] pixels = reader.Data;
                using (var bmp = new MemoryStream(reader.Data, false))
                {
                    var decoder = new BmpBitmapDecoder(bmp,
                                                       BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                    BitmapSource frame = decoder.Frames[0];
                    frame.Freeze();
                    return(new ImageData(frame, info));
                }
            }
        }
Exemple #5
0
 public override ImageMetaData ReadMetaData(Stream stream)
 {
     stream.Seek (4, SeekOrigin.Current);
     int data_size = stream.ReadByte() | stream.ReadByte() << 8 | stream.ReadByte() << 16 | stream.ReadByte() << 24;
     stream.Seek (4, SeekOrigin.Current);
     using (var reader = new Reader (stream, 0x22)) // BMP header
     {
         reader.Unpack();
         var bmp = reader.Data;
         if (bmp[0] != 'B' || bmp[1] != 'M')
             return null;
         int width = LittleEndian.ToInt32 (bmp, 0x12);
         int height = LittleEndian.ToInt32 (bmp, 0x16);
         int bpp = LittleEndian.ToInt16 (bmp, 0x1c);
         return new GrdMetaData
         {
             Width = (uint)width,
             Height = (uint)height,
             BPP = bpp,
             DataSize = data_size,
         };
     }
 }