Ejemplo n.º 1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            PicturesList list = new PicturesList();

            if (opnDialog.ShowDialog() == DialogResult.OK)
            {
                list = binSerializer.DeserializeImages(opnDialog.FileName, ref readedBytes);
            }

            lsbPictures.Items.Clear();
            imageList.RemoveRange(0, imageList.Count);
            foreach (ImageInfo picture in list)
            {
                lsbPictures.Items.Add(picture.Date.ToString());
                imageList.Add(picture);
            }
        }
        public byte[] SerializeImages(PicturesList images, string path)
        {
            byte[]     result;
            FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
            long       length;
            //to binary
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(fs, images);

            length = fs.Length;
            result = new byte[length];
            fs.Seek(0, SeekOrigin.Begin);
            fs.Read(result, 0, (int)length);
            fs.Close();
            return(result);
        }