Demo entry 6789488

1

   

Submitted by anonymous on Apr 29, 2019 at 14:48
Language: C#. Code size: 10.4 kB.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Pic
{
    public partial class Form1 : Form
    {
        int y1, y2, y3;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.AllowDrop = true;
            pictureBox2.AllowDrop = true;
            pictureBox3.AllowDrop = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
        }

        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            PictureBox pb = (PictureBox)sender;
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (pb.Image != null)
                {
                    int xp = Convert.ToInt32(e.X);
                    int yp = Convert.ToInt32(e.Y);
                    double xi, yi;
                    xi = Convert.ToDouble(xp) / Convert.ToDouble(pb.Width) * Convert.ToDouble(pb.Image.Width);
                    yi = Convert.ToDouble(yp) / Convert.ToDouble(pb.Height) * Convert.ToDouble(pb.Image.Height);

                    if (pb == pictureBox1)
                    {
                        label1.Text = Convert.ToString(Convert.ToInt32(xi)) + " X " + Convert.ToString(Convert.ToInt32(yi));
                        y1 = Convert.ToInt32(yi);
                    }
                    else if (pb == pictureBox2)
                    {
                        label2.Text = Convert.ToString(Convert.ToInt32(xi)) + " X " + Convert.ToString(Convert.ToInt32(yi));
                        y2 = Convert.ToInt32(yi);
                    }
                    else
                    {
                        label3.Text = Convert.ToString(Convert.ToInt32(xi)) + " X " + Convert.ToString(Convert.ToInt32(yi));
                        y3 = Convert.ToInt32(yi);
                    }
                    /*Graphics g = Graphics.FromImage(pb.Image);
                    g.DrawLine(Pens.Black, 0, Convert.ToInt32(yi), pb.Image.Width, Convert.ToInt32(yi));
                    pb.Invalidate();*/
                }
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
                if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
                    pb.Image = Image.FromFile(openFileDialog1.FileName);                                
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            PictureBox pb = (PictureBox)sender;
            if (pb == pictureBox1)
            {
                label1.Text = "x X y";
                y1 = 0;
            }
            else if (pb == pictureBox2)
            {
                label2.Text = "x X y";
                y2 = 0;
            }
            else
            {
                label3.Text = "x X y";
                y3 = 0;
            }
        }

        private void msAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show("                                                            ТюмГУ \r\n                                       Институт Государства и Права \r\n\r\n    Программа 'Панорама' является частью курсовой работы на тему \r\n                   'Криминалистическая фотография и видеозапись' \r\n\r\n\r\n                                              Студент группы 26ПОНБ142 Тадыкина А.П.\r\n\r\n\r\n                                                      Copyright © Тадыкина Анастасия 2018", "О программе...");
        }

        private void msCopy_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image != null && pictureBox2.Image != null && pictureBox3.Image != null 
                && label1.Text != "x X y" && label2.Text != "x X y" && label3.Text != "x X y")
            {
                int dy1 = 0, dy2 = 0, dy3 = 0, max = 0, maxH = 0;

                //Поиск максимального значения отступа от 0 (по оси y)
                max = Math.Max(y1, y2);
                max = Math.Max(max, y3);
                
                dy1 = max - y1;
                dy2 = max - y2;
                dy3 = max - y3;

                maxH = Math.Max(pictureBox1.Image.Height, pictureBox2.Image.Height);
                maxH = Math.Max(maxH, pictureBox3.Image.Height);

                Bitmap res = new Bitmap(pictureBox1.Image.Width + pictureBox2.Image.Width + pictureBox3.Image.Width, maxH);

                Graphics g = Graphics.FromImage(res);
                g.DrawImage(pictureBox1.Image, 0, dy1, pictureBox1.Image.Width, pictureBox1.Image.Height);
                g.DrawImage(pictureBox2.Image, pictureBox1.Image.Width, dy2, pictureBox2.Image.Width, pictureBox2.Image.Height);
                g.DrawImage(pictureBox3.Image, pictureBox1.Image.Width + pictureBox2.Image.Width, dy3, pictureBox3.Image.Width, pictureBox3.Image.Height);

                if (MSAutoH.Checked)
                {
                    max = Math.Max(dy1, dy2);
                    max = Math.Max(max, dy3);
                    g.DrawImage(res, 0, -max, res.Width, res.Height);

                    int minHd = Math.Min(pictureBox1.Image.Height + dy1, pictureBox2.Image.Height + dy2);
                    minHd = Math.Min(minHd, pictureBox3.Image.Height + dy3);
                    res = res.Clone(new Rectangle(0, 0, pictureBox1.Image.Width + pictureBox2.Image.Width + pictureBox3.Image.Width, minHd - max), res.PixelFormat);
                }
                Clipboard.SetImage(res);

                tmess.Interval = 3000;
                lmess.Visible = true;
                lmess.Text = "Результат помещён в буфер обмена. \r\n Воспользуйтесь функцией 'Вставить' в Word";
                tmess.Start();
            }
            else
            {
                tmess.Interval = 3000;
                lmess.Visible = true;
                lmess.Text = "Не отмечены координаты глаз!";
                tmess.Start();
            }
        }

        private void msHelp_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 1. Загрузите изображения двумя доступными способами: \r\n     a. щёлкнуть ЛКМ по области изображения  \r\n     b. перетащить из проводника \r\n 2. Отметьте координаты глаз ПКМ \r\n 3. Получить результат работы можно: \r\n     a. скопировав с помощью кнопки в правом нижнем углу (√)  \r\n     b. сохранив изображение (Файл/Сохранить как…) \r\n\r\n ЛКМ – левая кнопка мыши \r\n ПКМ – правая кнопка мыши \r\n", "Инструкция");
        }

        private void msClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void tmess_Tick(object sender, EventArgs e)
        {
            lmess.Text = "";
            lmess.Visible = false;
            tmess.Stop();
        }

        private void msSave_Click(object sender, EventArgs e)
        {
            if (pictureBox1.Image != null && pictureBox2.Image != null && pictureBox3.Image != null
                && label1.Text != "x X y" && label2.Text != "x X y" && label3.Text != "x X y")
            {
                int dy1 = 0, dy2 = 0, dy3 = 0, max = 0, maxH = 0;

                max = Math.Max(y1, y2);
                max = Math.Max(max, y3);

                dy1 = max - y1;
                dy2 = max - y2;
                dy3 = max - y3;

                maxH = Math.Max(pictureBox1.Image.Height, pictureBox2.Image.Height);
                maxH = Math.Max(maxH, pictureBox3.Image.Height);

                Bitmap res = new Bitmap(pictureBox1.Image.Width + pictureBox2.Image.Width + pictureBox3.Image.Width, maxH);

                Graphics g = Graphics.FromImage(res);
                g.DrawImage(pictureBox1.Image, 0, dy1, pictureBox1.Image.Width, pictureBox1.Image.Height);
                g.DrawImage(pictureBox2.Image, pictureBox1.Image.Width, dy2, pictureBox2.Image.Width, pictureBox2.Image.Height);
                g.DrawImage(pictureBox3.Image, pictureBox1.Image.Width + pictureBox2.Image.Width, dy3, pictureBox3.Image.Width, pictureBox3.Image.Height);

                if (MSAutoH.Checked)
                {
                    max = Math.Max(dy1, dy2);
                    max = Math.Max(max, dy3);
                    g.DrawImage(res, 0, -max, res.Width, res.Height);

                    int minHd = Math.Min(pictureBox1.Image.Height + dy1, pictureBox2.Image.Height + dy2);
                    minHd = Math.Min(minHd, pictureBox3.Image.Height + dy3);
                    res = res.Clone(new Rectangle(0, 0, pictureBox1.Image.Width + pictureBox2.Image.Width + pictureBox3.Image.Width, minHd - max), res.PixelFormat);
                }

                if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
                    res.Save(saveFileDialog1.FileName);
            }
            else
            {
                tmess.Interval = 3000;
                lmess.Visible = true;
                lmess.Text = "Не отмечены координаты глаз!";
                tmess.Start();
            }
        }

        private void pictureBox1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] fName = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (fName.Length == 1 && (fName[0].ToLower().EndsWith(".jpg") || fName[0].ToLower().EndsWith(".png") || fName[0].ToLower().EndsWith(".bmp") || fName[0].ToLower().EndsWith(".gif")))
                    e.Effect = DragDropEffects.Copy;
                else
                    e.Effect = DragDropEffects.None;
            }
        }

        private void pictureBox1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] fName = (string[])e.Data.GetData(DataFormats.FileDrop);
                PictureBox pb = (PictureBox)sender;                
                pb.Image = Image.FromFile(fName[0]);
            }
        }
    }
}

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).