cyotek/Cyotek.Windows.Forms.ImageBox

Creating and Zooming Graphics

Opened this issue · 0 comments

Hi,

I placed below code in constructor of form

using (Graphics g = imageBox1.CreateGraphics())
{
  Pen blackPen = new Pen(Color.Black, 3);
  int x1 = 100;
  int y1 = 100;
  int x2 = 500;
  int y2 = 100;
  g.DrawLine(blackPen, x1, y1, x2, y2);
}

it didn't create the line. However if i use paint event, it draws the line

private void imageBox1_Paint(object sender, PaintEventArgs e)
{
    Pen blackPen = new Pen(Color.Black, 3);
    int x1 = 100;
    int y1 = 100;
    int x2 = 500;
    int y2 = 100;
    e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
}
  1. is there a way to draw graphics from first method
  2. how to zoom graphics ? when i scroll only image scrolls, graphics on it stays in the same place. is there a way to scroll both Graphics and Image together?

Thanks & Regards
Prakash

Update: we can use combination of Graphics.TranslateTransform(float dx, float dy) and Graphics.ScaleTransform (float sx, float sy).

I was thinking of passing imagebox1.Zoom value into Graphics.ScaleTransform and Mouse location on picture in Graphics.TranslateTransform

so I tried to zoom the graphics by using imagebox1.Zoom in ImageBox ZoomChanged event , its not working well.

I wanted to temporarily draw this graphic ,Directly drawing on image is not an option ..
so I was trying to set a point/circle on picture at location x=50, y =50. not sure on which location in imageBox i need to place this point and properly handle zooming + panning of this point/circle(System.Drawing.Graphic)