Пример #1
0
        private void saveB_Click(object sender, EventArgs e)
        {
            panel1.Refresh();
            //Bitmap bmp = new Bitmap(this.Size.Width, this.Size.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            //Graphics gfx = Graphics.FromImage(bmp);
            //gfx.CopyFromScreen(this.Location.X+17, this.Location.Y+65, 0, 0, this.panel1.Size, CopyPixelOperation.SourceCopy);
            //Создаем Graphics для PictureBox
            Graphics g1 = panel1.CreateGraphics();

            ////Создаем объект Image с теми же параметрами, что и PictureBox
            Image img = new Bitmap(panel1.ClientRectangle.Width, panel1.ClientRectangle.Height, g1);

            //Создаем новый Graphics для рисования на изображении
            Graphics g2 = Graphics.FromImage(img);

            //Получаем контексты рисования для PictureBox и Image из объектов Graphics
            IntPtr dc1 = g1.GetHdc();
            IntPtr dc2 = g2.GetHdc();

            //Копируем изображение с PictureBox на Image
            BitBlt(dc2, 0, 0, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);

            //Освобождаем ресурсы контекстов рисования
            g1.ReleaseHdc(dc1);
            g2.ReleaseHdc(dc2);

            //Сохраняем изображение в файл
            //img.Save("out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            SaveFileDialog savedialog = new SaveFileDialog();
            savedialog.Title = "Сохранить картинку как ...";
            savedialog.OverwritePrompt = true;
            savedialog.CheckPathExists = true;
            savedialog.Filter =
                "AC File(*.ac)|*.ac|" +
                "Bitmap File(*.bmp)|*.bmp|" +
                "GIF File(*.gif)|*.gif|" +
                "JPEG File(*.jpg)|*.jpg|" +
                "TIF File(*.tif)|*.tif|" +
                "PNG File(*.png)|*.png";
            savedialog.ShowHelp = true;
            // If selected, save
            if (savedialog.ShowDialog() == DialogResult.OK)
            {
                // Get the user-selected file name
                string fileName = savedialog.FileName;
                // Get the extension
                string strFilExtn =
                    fileName.Remove(0, fileName.Length - 3);
                // Save file
                switch (strFilExtn)
                {
                    case "bmp":
                        img.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
                        break;
                    case "jpg":
                        img.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        break;
                    case "gif":
                        img.Save(fileName, System.Drawing.Imaging.ImageFormat.Gif);
                        break;
                    case "tif":
                        img.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff);
                        break;
                    case "png":
                        img.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                        break;
                    case ".ac":
                        ObjSer os = new ObjSer();
                        int pictureNumber = 0;
                        foreach (DragPictureBox pic in pictureBox1)
                        {
                            SerPic sp = new SerPic(pic.Location.X, pic.Location.Y, pic.Width, pic.Height, ImageToString(pic.Image));
                            os.AddToPicList(sp);
                            foreach (Control c in pic.Controls)
                            {
                                if (c is AlphaBlendTextBox)
                                {
                                    SerText st = new SerText(c.Location.X, c.Location.Y, c.Font.Name, c.Font.Size,
                                        c.ForeColor, pictureNumber, c.Text,c.Font.Style/*,c.Font.Style*/);
                                    os.AddToTextList(st);
                                }
                            }
                            pictureNumber++;
                        }
                        Stream TestFileStream = File.Create(fileName);
                        BinaryFormatter serializer = new BinaryFormatter();
                        serializer.Serialize(TestFileStream, os);
                        TestFileStream.Close();
                        break;
                    default:
                        break;
                }
            }
        }
Пример #2
0
        private void saveB_Click(object sender, EventArgs e)
        {
            panel1.Refresh();
            //Bitmap bmp = new Bitmap(this.Size.Width, this.Size.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            //Graphics gfx = Graphics.FromImage(bmp);
            //gfx.CopyFromScreen(this.Location.X+17, this.Location.Y+65, 0, 0, this.panel1.Size, CopyPixelOperation.SourceCopy);
            //Создаем Graphics для PictureBox
            Graphics g1 = panel1.CreateGraphics();

            ////Создаем объект Image с теми же параметрами, что и PictureBox
            Image img = new Bitmap(panel1.ClientRectangle.Width, panel1.ClientRectangle.Height, g1);

            //Создаем новый Graphics для рисования на изображении
            Graphics g2 = Graphics.FromImage(img);

            //Получаем контексты рисования для PictureBox и Image из объектов Graphics
            IntPtr dc1 = g1.GetHdc();
            IntPtr dc2 = g2.GetHdc();

            //Копируем изображение с PictureBox на Image
            BitBlt(dc2, 0, 0, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);

            //Освобождаем ресурсы контекстов рисования
            g1.ReleaseHdc(dc1);
            g2.ReleaseHdc(dc2);

            //Сохраняем изображение в файл
            //img.Save("out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            SaveFileDialog savedialog = new SaveFileDialog();

            savedialog.Title           = "Сохранить картинку как ...";
            savedialog.OverwritePrompt = true;
            savedialog.CheckPathExists = true;
            savedialog.Filter          =
                "AC File(*.ac)|*.ac|" +
                "Bitmap File(*.bmp)|*.bmp|" +
                "GIF File(*.gif)|*.gif|" +
                "JPEG File(*.jpg)|*.jpg|" +
                "TIF File(*.tif)|*.tif|" +
                "PNG File(*.png)|*.png";
            savedialog.ShowHelp = true;
            // If selected, save
            if (savedialog.ShowDialog() == DialogResult.OK)
            {
                // Get the user-selected file name
                string fileName = savedialog.FileName;
                // Get the extension
                string strFilExtn =
                    fileName.Remove(0, fileName.Length - 3);
                // Save file
                switch (strFilExtn)
                {
                case "bmp":
                    img.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
                    break;

                case "jpg":
                    img.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;

                case "gif":
                    img.Save(fileName, System.Drawing.Imaging.ImageFormat.Gif);
                    break;

                case "tif":
                    img.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff);
                    break;

                case "png":
                    img.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                    break;

                case ".ac":
                    ObjSer os            = new ObjSer();
                    int    pictureNumber = 0;
                    foreach (DragPictureBox pic in pictureBox1)
                    {
                        SerPic sp = new SerPic(pic.Location.X, pic.Location.Y, pic.Width, pic.Height, ImageToString(pic.Image));
                        os.AddToPicList(sp);
                        foreach (Control c in pic.Controls)
                        {
                            if (c is AlphaBlendTextBox)
                            {
                                SerText st = new SerText(c.Location.X, c.Location.Y, c.Font.Name, c.Font.Size,
                                                         c.ForeColor, pictureNumber, c.Text, c.Font.Style /*,c.Font.Style*/);
                                os.AddToTextList(st);
                            }
                        }
                        pictureNumber++;
                    }
                    Stream          TestFileStream = File.Create(fileName);
                    BinaryFormatter serializer     = new BinaryFormatter();
                    serializer.Serialize(TestFileStream, os);
                    TestFileStream.Close();
                    break;

                default:
                    break;
                }
            }
        }
Пример #3
0
 public void AddToTextList(SerText t)
 {
     text.Add(t);
 }
Пример #4
0
 public void AddToTextList(SerText t)
 {
     text.Add(t);
 }