开发者

plotting points over an image

I've an image over which i need to plot some points. The problem is that the points appear for a fraction of a second and then disappear. How to make the poin开发者_如何学Gots permanent over the image. I've set the image as the background of the form.

I'm working on C# .net framework. Thanks.


You could create a Graphics object for the image and then draw these points on the image. That make them permanent indeed. Like so:

public void ImageDrawing()
{
    // NOTE: There are several ways you can load an image
    // this is just using an existing file on disk
    var img = Image.FromFile("myimage.jpg");
    using (var g = Graphics.FromImage(img))
    {
        g.DrawLine(Pens.AliceBlue, new Point(), new Point(img.Width - 1, img.Height - 1));
    }
    this.BackgroundImage = img;
}

That will draw an AliceBlue line from the top left corner to the bottom right corner.


We need to see code. My guess would be that you are drawing using CreateGraphics and not doing so in OnPaint, so it is simply wiped out when the control is repainted and you never paint it again. Override OnPaint and do all of your drawing there (or post a relevant example)


In your case just put your point plotting code to OnPaint event handler of the form. Your points dissapears because of form repaint routine

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜