Hi,
I created small application, which is suppose to draw objects on jpg file ( loaded into picturebox ). Coordinates of objects are provided by user ( by clicking on picturebox ). Here are some code samples:
So - the problem is that ellipses are drawn with delay - I mean that first is drawn on 2nd click, 2nd ellipse on 3rd click, and so on. I assume that there is issue with validating picturebox, but I can't find what I'm doing wrong :/
There is no issue at all if I switch from "g = Graphics.FromIm age(pictureBox1 .Image)" to "g = e.Graphics" but if I do this I can't save image properly ( drawn object just disappear ).
Any suggestions ? :)
Regards,
Piotr
I created small application, which is suppose to draw objects on jpg file ( loaded into picturebox ). Coordinates of objects are provided by user ( by clicking on picturebox ). Here are some code samples:
Code:
public void ryspkt(MouseEventArgs e)
{
if (pictureBox1.Image != null)
{
if (e.Button == MouseButtons.Left)
{
rect[nrprs++] = new Rectangle(e.X, e.Y,2,2);
pictureBox1.Invalidate();
}
Code:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
ryspkt(e);
}
Code:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
//g = e.Graphics;
g = Graphics.FromImage(pictureBox1.Image);
for (int i = 0; i < nrprs; i++)
{
g.FillEllipse(b, rect[i]);
}
}
There is no issue at all if I switch from "g = Graphics.FromIm age(pictureBox1 .Image)" to "g = e.Graphics" but if I do this I can't save image properly ( drawn object just disappear ).
Any suggestions ? :)
Regards,
Piotr
Comment