Beispiel #1
0
        public static Ema Import(Stream stream, string name)
        {
            Ema ema = Import(stream);

            ema.Name = name;
            return(ema);
        }
Beispiel #2
0
        public static Ema Import(Stream stream)
        {
            Ema ema = new Ema();

            using (BinaryReader reader = new BinaryReader(stream))
            {
                byte[] imgData = reader.ReadToEnd();
                var    imgInfo = ImageInformation.FromMemory(imgData);

                ema.Data = new byte[imgData.Length + 13];
                BinaryWriter dataWriter = new BinaryWriter(new MemoryStream(ema.Data));
                dataWriter.Write(imgInfo.Width);
                dataWriter.Write(imgInfo.Height);

                string ext = Enum.GetName(typeof(ImageFileFormat), imgInfo.ImageFileFormat).ToLowerInvariant();
                dataWriter.Write((byte)'.');
                dataWriter.Write(Encoding.ASCII.GetBytes(ext));
                dataWriter.Write((byte)0);

                if (imgInfo.ImageFileFormat == ImageFileFormat.Bmp)
                {
                    dataWriter.Write((short)0);
                    dataWriter.Write(imgData, 2, imgData.Length - 2);
                }
                else
                {
                    dataWriter.Write(imgData);
                }
            }
            return(ema);
        }
Beispiel #3
0
        public static Ema Import(Stream stream)
        {
            Ema ema = new Ema();
            using (BinaryReader reader = new BinaryReader(stream))
            {
                byte[] imgData = reader.ReadToEnd();
                var imgInfo = ImageInformation.FromMemory(imgData);

                ema.Data = new byte[imgData.Length + 13];
                BinaryWriter dataWriter = new BinaryWriter(new MemoryStream(ema.Data));
                dataWriter.Write(imgInfo.Width);
                dataWriter.Write(imgInfo.Height);

                string ext = Enum.GetName(typeof(ImageFileFormat), imgInfo.ImageFileFormat).ToLowerInvariant();
                dataWriter.Write((byte)'.');
                dataWriter.Write(Encoding.ASCII.GetBytes(ext));
                dataWriter.Write((byte)0);

                if (imgInfo.ImageFileFormat == ImageFileFormat.Bmp)
                {
                    dataWriter.Write((short)0);
                    dataWriter.Write(imgData, 2, imgData.Length - 2);
                }
                else
                {
                    dataWriter.Write(imgData);
                }
            }
            return ema;
        }