コード例 #1
0
        private void ButtonSaveAsPicture_Click(object sender, EventArgs e)
        {
            var dialog = new SaveFileDialog();

            dialog.Filter = "Изображения в формате jpeg|*.jpg|Изображения в формате bmp|*.bmp";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                System.Drawing.Imaging.ImageFormat format = null;
                switch (dialog.FilterIndex)
                {
                case 1:     //jpeg
                    format = System.Drawing.Imaging.ImageFormat.Jpeg;
                    break;

                case 2:     //bmp
                    format = System.Drawing.Imaging.ImageFormat.Bmp;
                    break;

                default:     // png
                    format = System.Drawing.Imaging.ImageFormat.Png;
                    break;
                }


                mainBitmap = new Bitmap(pictureBox3.Width, pictureBox3.Height);

                using (Graphics graphics = Graphics.FromImage(mainBitmap))
                {
                    graphics.DrawImage(newBitmap, 0, 0);
                    graphics.DrawImage(listOfBitmap[0],
                                       pictureBox1.Location.X - pictureBox3.Location.X, pictureBox1.Location.Y - pictureBox3.Location.Y);
                    graphics.DrawImage(listOfBitmap[1],
                                       pictureBox2.Location.X - pictureBox3.Location.X, pictureBox2.Location.Y - pictureBox3.Location.Y);
                }

                SaveImage newImage = new SaveImage(mainBitmap);

                mainBitmap.Save(dialog.FileName, format);

                // создаем объект BinaryFormatter
                BinaryFormatter formatter = new BinaryFormatter();
                // получаем поток, куда будем записывать сериализованный объект
                using (FileStream fs = new FileStream(@"D:\testForLab\directoryOne\people.dat", FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, newImage);
                }
            }
        }
コード例 #2
0
        public void ParseFile(ComponentEntity currentComponent)
        {
            string fileName = string.Empty;
            var    dialog   = new OpenFileDialog();

            dialog.Filter = "Текстовые файлы|*.txt|VHDL файлы|*.vhd|DAT файлы|*.dat";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                fileName = dialog.FileName;
            }

            if (fileName.Contains("dat"))
            {
                using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    BinaryFormatter formatter = new BinaryFormatter();

                    SaveImage newImage = (SaveImage)formatter.Deserialize(fs);

                    pictureBox1.Hide();
                    pictureBox2.Hide();

                    pictureBox3.BackgroundImage = newImage.bitmap;
                }
            }
            else
            {
                try
                {
                    Parser parser = new Parser(fileName);
                    parser.ParseFile(currentComponent);
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }