-2

I would like to use GDI+ and C# to be able to draw lines consisting of images in WinForms.Please note that It is not to draw simple lines over an image but to draw lines made up of images like *******************************(each * is a specific image).

For example, i have an imageA, and the line will be like imageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageAimageA

Do you have an example or some advice?

vaj oja
  • 1,151
  • 2
  • 16
  • 47
  • possible duplicate of [how to draw a line on a image?](http://stackoverflow.com/questions/11402862/how-to-draw-a-line-on-a-image) – Mark Hall May 26 '14 at 15:32

3 Answers3

1

This question can be found with a little Google love in a couple of minutes. Try not to ask simple questions which have almost certainly been answered a hundred times over.

I searched for c# draw line on image in Google and the first link was a clean answer to your question

how to draw a line on a image?

Even the MSDN method description of DrawLine has an example.

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

Community
  • 1
  • 1
Spark
  • 1,007
  • 1
  • 8
  • 26
  • Sorry i didn't explain the question correctly.It is not to draw lines over an image but draw lines of images like *********************************** in which the line consists of many *. – vaj oja May 27 '14 at 05:38
0

I think what you are looking for is the following enter image description here

take the points of the star as lines. use the following function in Paint event.

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

Every line has a start point and end point. GDI+ Draw line function needs two points 1. start point of the line and end point of the line and pen to draw. A star is a combination of line

ImageObject is the Bitmap.

Razack
  • 1,826
  • 2
  • 16
  • 37
  • Please add a usable code sample, or explain how `StartPoint` and `EndPoint` should be used. – rhughes May 26 '14 at 05:04
  • Every line has a start point and end point. GDI+ Draw line function needs two points 1. start point of the line and end point of the line and pen to draw. A star is a combination of line..... – Razack May 26 '14 at 05:06
  • Thanks. In order to improve the quality of your answer, can you please include that information? – rhughes May 26 '14 at 05:07
0

You can use this to draw on your image:

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

The start and end points are 2-dimensional coordinates.

W0lfw00ds
  • 2,018
  • 14
  • 23