private ZoomPicBox CreatePictureBox(Bitmap image)
        {
            // New ZoomPicBox
            ZoomPicBox picBox = new ZoomPicBox();

            picBox.Image             = image;
            picBox.Anchor            = AnchorStyles.Top | AnchorStyles.Left;
            picBox.Top               = 0;
            picBox.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            picBox.MouseClick       += PictureBox_ClickEvent;
            return(picBox);
        }
Exemple #2
0
        private void PicBox_MouseClick(object sender, MouseEventArgs e)
        {
            if (stitchModule == null)
            {
                return;
            }

            ZoomPicBox picBox = sender as ZoomPicBox;

            if ((picBox == null) || (picBox.Image == null))// ||  (e.Button != MouseButtons.Left))
            {
                return;
            }

            List <Point3D> points;

            switch (picBox.Name)
            {
            case "picBoxFirst":
                points = stitchModule.FirstPoints;
                break;

            case "picBoxSecond":
                points = stitchModule.SecondPoints;
                break;

            default:
                points = null;
                break;
            }

            // Left mouse button - add points
            if (e.Button == MouseButtons.Left)
            {
                if ((points != null) && (points.Count < 4))
                {
                    points.Add(new Point3D(picBox.CurrentState.OriginalX,
                                           picBox.CurrentState.OriginalY, 0));
                }
            }

            // Right mouse button - remove points
            if ((e.Button == MouseButtons.Right) &&
                (points != null) && (points.Count != 0))
            {
                points.RemoveAt(points.Count - 1);
            }

            picBox.Refresh();
        }
        public void AddImage(Panel panel, QuickStitch stitchModule, Side side)
        {
            string fileName = OpenImageFile();

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            Bitmap     image     = new Bitmap(fileName);
            ImageData  imageData = new ImageData(fileName, image);
            ZoomPicBox picBox    = CreatePictureBox(image);

            panel.Controls.Add(picBox);

            switch (side)
            {
            case Side.Left:
                // Insert at beginning
                stitchModule.ImageDataCollection.Insert(0, imageData);
                ImageBoxes.Insert(0, picBox);
                ResizePicBoxes(panel);
                break;

            case Side.Right:
                // Insert at the end
                stitchModule.ImageDataCollection.Add(imageData);
                ImageBoxes.Add(picBox);
                ResizePicBoxes(panel);
                break;

            case Side.Main:
                stitchModule.MainImageData = imageData;
                stitchModule.ImageDataCollection.Add(imageData);
                picBox.Size  = panel.ClientSize;
                MainImageBox = picBox;
                ImageBoxes.Add(picBox);
                break;

            default:
                break;
            }

            panel.Refresh();
        }
Exemple #4
0
        //private void WriteRegistryData()
        //{
        //    if ((stitchModule == null) ||
        //        (stitchModule.FirstPoints.Count != QuickStitch.StitchPointsCount) ||
        //        (stitchModule.SecondPoints.Count != QuickStitch.StitchPointsCount))
        //    {
        //        return;
        //    }

        //    RegistryKey rk = null;
        //    try
        //    {
        //        rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\CADBEST\\QuickStitch");
        //        List<Point3D> points = stitchModule.FirstPoints;
        //        for (int i = 0; i < points.Count; i++)
        //        {
        //            rk.SetValue(string.Format("FirstPoints{0}", i), points[i].ToString());
        //        }

        //        points = stitchModule.SecondPoints;
        //        for (int i = 0; i < points.Count; i++)
        //        {
        //            rk.SetValue(string.Format("SecondPoints{0}", i), points[i].ToString());
        //        }

        //        if (picBoxFirst.FileName != null)
        //            rk.SetValue("FirstBmp", picBoxFirst.FileName);
        //        if (picBoxSecond.FileName != null)
        //            rk.SetValue("SecondBmp", picBoxSecond.FileName);
        //    }
        //    finally
        //    {
        //        rk.Dispose();
        //    }
        //}

        //private void ReadRegistryData()
        //{
        //    RegistryKey rk = null;
        //    try
        //    {
        //        rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\CADBEST\\QuickStitch");
        //        string fileName1 = (string)rk.GetValue("FirstBmp");
        //        string fileName2 = (string)rk.GetValue("SecondBmp");

        //        if ((fileName1 == null) || (fileName2 == null))
        //            return;

        //        LoadImages(fileName1, fileName2);

        //        // Load points
        //        for (int i = 0; i < QuickStitch.StitchPointsCount; i++)
        //        {
        //            string point = (string)rk.GetValue(string.Format("FirstPoints{0}", i));
        //            stitchModule.FirstPoints.Add(new Point3D(point));
        //        }

        //        for (int i = 0; i < QuickStitch.StitchPointsCount; i++)
        //        {
        //            string point = (string)rk.GetValue(string.Format("SecondPoints{0}", i));
        //            stitchModule.SecondPoints.Add(new Point3D(point));
        //        }
        //    }
        //    finally
        //    {
        //        rk.Dispose();
        //    }
        //}

        private void PicBox_Paint(object sender, PaintEventArgs e)
        {
            if (stitchModule == null)
            {
                return;
            }
            ZoomPicBox picBox = sender as ZoomPicBox;

            if (picBox == null)
            {
                return;
            }

            List <Point3D> points;

            switch (picBox.Name)
            {
            case "picBoxFirst":
                points = stitchModule.FirstPoints;
                break;

            case "picBoxSecond":
                points = stitchModule.SecondPoints;
                break;

            default:
                points = null;
                break;
            }

            foreach (Point3D p in points)
            {
                // Draw circle at every clicked spot in the image
                // with center at the clicked spot, and radius set
                // by the constant
                e.Graphics.DrawEllipse(
                    pointsPen,
                    (float)(p.X - PointVisualizeRadius / 2f),
                    (float)(p.Y - PointVisualizeRadius / 2f),
                    PointVisualizeRadius,
                    PointVisualizeRadius);
            }
        }