Click here to Skip to main content
16,016,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have work with imagen editor, in where load image and tried make Zoom in/out together with draw lines.

- In the moment of make Zoom the lines can´t resize de lines, only cant zoom the graphics and the coordinates not rotate.

- For rotate can´t resixe the lines, only can rotate the graphics, the coordinates not rotate.

someone can help me!! thanks.

For draw the line in the picture:

C#
private void image_Paint(object sender, PaintEventArgs e)
        {
            int bDos, dDos, aDos, cDos; ;
            double puntoADos, puntoBDos, zDos, mmDos, resultDos;
            e.Graphics.ScaleTransform(1.06F, 1.06F);
            if (linea.BackColor == Color.FromArgb(255, 0, 0) || girar.BackColor == Color.FromArgb(255, 0, 0)  || mover.BackColor == Color.FromArgb(255, 0, 0) || zoom.BackColor == Color.FromArgb(255, 0, 0) || zoomOut.BackColor == Color.FromArgb(255, 0, 0))
             { 
                // Dibuja los segmentos.
                for (int i = 0; i < Pt1.Count; i++)
                { 
                    // Dibuja el segmento.
                    //Pen greenPen = new Pen(Color.FromArgb(255, 0, 255, 0), 5);
                    Pen greenPen = new Pen(Colores.BackColor);
                    e.Graphics.DrawLine(greenPen, Pt1[i], Pt2[i]);
                }

                int Talvez = 0;
                // Dibuja el final de los puntos.
                foreach (Point pt in Pt1)
                {
                    Rectangle rect = new Rectangle(pt.X - object_radius, pt.Y - object_radius, 2 * object_radius + 1, 2 * object_radius + 1);
                    //Color de fondo del punto de inicio de la linea.
                    e.Graphics.FillEllipse(Brushes.Red, rect);
                    //Color de contorno del punto de inicio.
                    e.Graphics.DrawEllipse(Pens.Red, rect);
                    aDos = pt.X;
                    cDos = pt.Y;

                    Point ptFinal = Pt2[Talvez];
                    // pt.
                    Rectangle RectFinal = new Rectangle(ptFinal.X - object_radius, ptFinal.Y - object_radius, 2 * object_radius + 1, 2 * object_radius + 1);
                    // //Color del punto final de la linea.
                    e.Graphics.FillEllipse(Brushes.Red, RectFinal);
                    //Color del contorno del circulo del punto final.
                    e.Graphics.DrawEllipse(Pens.Red, RectFinal);
                    bDos = ptFinal.X;
                    dDos = ptFinal.Y;

                    puntoADos = Math.Pow(bDos - aDos, 2);
                    puntoBDos = Math.Pow(dDos - cDos, 2);

                    zDos = Math.Sqrt(puntoADos + puntoBDos);
                    mmDos = zDos / 3.779527559;

                    resultDos = Math.Round(mmDos, 2);

                    /////////////// MOSTRAMOS LA CAJA DE TEXTO AL FINAL DE LA LINEA /////////////////////////
                    string drawString = Convert.ToString(resultDos);
                    Font drawFont = new Font("Arial", 8);

                    ///// Creamos el color del rectangulo al final de la linea ///////////
                    SolidBrush myBrush = new SolidBrush(Color.FromArgb(100, 245, 171, 0));
                    e.Graphics.FillRectangle(myBrush, new Rectangle(ptFinal.X + 5, ptFinal.Y + 2, 60, 20));

                    ///////////// Definimos el color del texto del resultado /////////
                    SolidBrush drawBrush = new SolidBrush(Color.Yellow);
                    e.Graphics.DrawString(" " + drawString + " mm", drawFont, drawBrush, ptFinal.X + 5, ptFinal.Y + 5);

                    Talvez++;

                    e.Graphics.Transform = MyMatrix; 
                }

                // Muestra la construccion de la linea.
                if (IsDrawing)
                { 
                    //Color de linea al momento de trazarla.
                    Pen greenPen = new Pen(Colores.BackColor); 

                    e.Graphics.DrawLine(greenPen, NewPt1, NewPt2);
                    e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                    e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                }
                /* // Ubicación de la basura.
                RectangleF trash_rect = new RectangleF(50, 50,
                    TrashWidth, TrashHeight);
                e.Graphics.DrawImage(
                    Properties.Resources.basura,
                    trash_rect);*/
                }

            }


For change the cursor for draw or move pictureBox:

C#
// Inicia el dibujado de la linea.
      private void image_MouseMove(object sender, MouseEventArgs e)
      {
          if (linea.BackColor == Color.FromArgb(255, 0, 0) || zoom.BackColor == Color.FromArgb(255, 0, 0))
          {
              Cursor new_cursor = Cursors.Cross;

              // Verificamos que tipo de cursor se encuentra por encima del picturebox
              Point hit_point;
              int segment_number;

              if (MouseIsOverEndpoint(e.Location, out segment_number, out hit_point))
              {
                  new_cursor = Cursors.Hand;
              }
              else if (MouseIsOverSegment(e.Location, out segment_number))
              {
                  new_cursor = Cursors.Hand;
              }

               //Cambia de cursor.
              if (image.Cursor != new_cursor)
                  image.Cursor = new_cursor;

              image.Refresh();
          }

          if (mover.BackColor == Color.FromArgb(255, 0, 0))
          {
              if (e.Button == MouseButtons.Left)
              {
                  panel1.Location = new Point(panel1.Left + e.X - izquierdo, panel1.Top + e.Y - alto);
              }
          }

      }


What I have tried:

- Can make Zoom in/out in the picturebox with image.Size = new Size(image.Width + 50, image.Height + 50).

- For Zoom graphics occupy e.graphics.ScaledTransform(1.06F, 1.06F);

- this is link where this the application https://1drv.ms/f/s!ArkkNJAikHkShFAoiXCExZw3ILAf
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900