【问题标题】:Draw graphical lines(lines composed of graphics) in Win Forms with C#用C#在Win Forms中绘制图形线(由图形组成的线)
【发布时间】:2014-05-26 02:44:35
【问题描述】:

我想用GDI+和C#在WinForms中画出由图像组成的线条。请注意,不是在图像上画简单的线条,而是画由图像组成的线条,如** *****************************(每个 * 是一个特定的图像)。

例如,我有一个imageA,这条线就像imageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageA

你有例子或建议吗?

【问题讨论】:

标签: c# winforms gdi+


【解决方案1】:

这个问题可以在几分钟内用一点谷歌的爱找到。尽量不要问几乎肯定已经回答过一百次的简单问题。

我在 Google 中搜索了 c# draw line on image,第一个链接是对您问题的明确回答

how to draw a line on a image?

连DrawLine的MSDN方法描述都有例子。

http://msdn.microsoft.com/en-us/library/f956fzw1(v=vs.110).aspx

【讨论】:

  • 对不起,我没有正确解释这个问题。不是在图像上画线,而是在图像上画线,如 ***************** ****************** 其中一行包含许多 *.
【解决方案2】:

我认为您正在寻找的是以下内容

以星星的点为线。在 Paint 事件中使用以下函数。

void Draw(Graphics g)
{
   g.DrawImage(ImageObject, ptOrgin);
   DrawLine(objPen, StartPoint, EndPoint);//draw all line of the star
}

每一行都有起点和终点。 GDI+画线功能需要两个点 1. 线的起点和线的终点以及画笔。星星是线条的组合

ImageObject 是位图。

【讨论】:

  • 请添加一个可用的代码示例,或者说明应该如何使用StartPointEndPoint
  • 每一行都有起点和终点。 GDI+画线功能需要两个点 1. 线的起点和线的终点以及画笔。星星是线条的组合.....
  • 谢谢。为了提高您的回答质量,您能否提供该信息?
【解决方案3】:

您可以使用它在您的图像上绘图:

public void DrawLineOnImage(Image image, Color lineColor, float lineWeight,
                            System.Drawing.Point lineStart, System.Drawing.Point lineEnd)
{
   // This methods draws a line on the image given as parameter

   try
   {
      // Check the parameters
      if (image == null || lineColor == null || lineStart == null || lineWeight == null || lineWeight <= 0) { MessageBox.Show("Invalid parameters!"); return; }

      // Draw a line on the image
      using (Graphics g = Graphics.FromImage(image))
      using (Pen pen = new Pen(lineColor, lineWeight))
      {
         // Draw the line
         g.DrawLine(pen, lineStart, lineEnd);
      }
   }

   catch (Exception ex) { MessageBox.Show(ex.Message); }
}

起点和终点是二维坐标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2014-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多