Ejemplo n.º 1
0
        public static void Save(string path, PllFileFormat file)
        {
            if (file.Image != null)
            {
                var pict = new Picture(file.Image);
                byfferArray = pict.BytesBuffer;

                using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))

                    using (BinaryWriter binWriter = new BinaryWriter(fs))
                    {
                        binWriter.Write(file.PCName);
                        binWriter.Write(file.Image.Width);
                        binWriter.Write(file.Image.Height);
                        binWriter.Write(pict.Channels);
                        binWriter.Write(pict.PixelsCountWithChannels);
                        binWriter.Write(pict.BytesBuffer);
                    }
            }
        }
Ejemplo n.º 2
0
        public static PllFileFormat Load(string path)
        {
            PllFileFormat file = null;

            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BinaryReader binReader = new BinaryReader(fs))
                {
                    string PCName = binReader.ReadString();
                    Width    = binReader.ReadInt32();
                    Height   = binReader.ReadInt32();
                    Channels = binReader.ReadInt32();
                    PixelsCountWithChannels = binReader.ReadInt32();
                    byfferArray             = binReader.ReadBytes(PixelsCountWithChannels);

                    var bufferPixelsPtr = GCHandle.Alloc(byfferArray, GCHandleType.Pinned);
                    var image           = new Bitmap(Width, Height, Width * Channels,
                                                     System.Drawing.Imaging.PixelFormat.Format32bppArgb, bufferPixelsPtr.AddrOfPinnedObject());

                    file = new PllFileFormat(PCName, image);
                }
            return(file);
        }