在图像上绘制点

发布于 2024-10-21 15:01:11 字数 104 浏览 5 评论 0原文

我有一张图像,需要在其上绘制一些点。问题是这些点只出现几分之一秒,然后就消失了。如何使点永久显示在图像上。我已将图像设置为表单的背景。

我正在研究 C# .net 框架。 谢谢。

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 points permanent over the image. I've set the image as the background of the form.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

回梦 2024-10-28 15:01:11

您可以为图像创建一个 Graphics 对象,然后在图像上绘制这些点。这确实使它们永久存在。就像这样:

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;
}

这将从左上角到右下角绘制一条 AliceBlue 线。

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.

清浅ˋ旧时光 2024-10-28 15:01:11

我们需要查看代码。我的猜测是,您正在使用 CreateGraphics 进行绘制,而不是在 OnPaint 中进行绘制,因此当重新绘制控件时,它会被简单地擦除,并且您再也不会绘制它。覆盖 OnPaint 并在那里完成所有绘图(或发布相关示例)

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)

只是一片海 2024-10-28 15:01:11

在您的情况下,只需将点绘制代码放入表单的 OnPaint 事件处理程序中即可。由于表单重绘例程,您的积分消失了

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文