how to draw a line in .net like photoshop

Posted by Shanky11 under C# on 9/24/2013 | Points: 10 | Views : 1832 | Status : [Member] | Replies : 1
how to draw a line like photoshop on a picture
length ishould bu dynamic
user will scroll that line like in photshop




Responses

Posted by: Sheonarayan on: 9/24/2013 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Shanky,

Drawing lines are possible in C#, however if you really need real time you might be using HTML5 Cavas with the help of JavaScript. Read more about HTML5 Canvas here http://www.dotnetfunda.com/articles/show/1940/introduction-to-canvas-in-html5.

To draw a line in C#, you can follow below approach

Bitmap image = new Bitmap(width, count);
Graphics g = null;
try
{
g = Graphics.FromImage(image);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Font f = new Font("Arial", textSize, FontStyle.Regular);
SolidBrush b = new SolidBrush(Color.SkyBlue);
g.FillRectangle(b, 0, 0, 400, count);
g.DrawString(textToWrite, f, Brushes.Blue, 2, 5);
g.DrawLine(new Pen(Color.Blue, 1), new Point(5, 25), new Point(100, 0));
g.DrawLine(new Pen(Color.White, 1), new Point(60, 10), new Point(120, 28));


f.Dispose();
image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

}
catch (Exception ee)
{
context.Response.Write(ee.Message.ToString());
}
finally
{
image.Dispose();
g.Dispose();
}

Notice DrawLine in the above code snippet.

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response