Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi!
i have a widows form in c#. what i want is to create an app that draw vertical line on a bitmap image. for that i wrote the following code:
private void Form1_Load(object sender, EventArgs e)
{
Bitmap bmOriginal = new Bitmap("kpk.bmp");
Rectangle cloneRect = new Rectangle(0,0 , 200, 200);
System.Drawing.Imaging.PixelFormat format =
bmOriginal.PixelFormat;

Bitmap bmTile1 = bmOriginal.Clone(cloneRect, format);
pictureBox1.Image = bmTile1;

}
but when i run the app is does not show the lines on image.i tried to change the values in ractangle but it didnt effect. can somebody tells me what wrong and what i need to do.?or any other C# source for that....?
thanks in advance
Posted
Updated 9-Feb-12 21:00pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Feb-12 3:00am    
Drawing on an image? Where?!
--SA
saifullahiit 10-Feb-12 3:02am    
i m not drawing image. i want to draw lines on image.
Sergey Alexandrovich Kryukov 10-Feb-12 3:00am    
And why?
--SA

That might have something to do with you not drawing any lines...
Try adding this:
C#
Bitmap bmTile1 = bmOriginal.Clone(cloneRect, format);
using (Graphics g = Graphics.FromImage(bmTile1))
    {
    g.DrawLine(Pens.White, 0, 0, 100, 100);
    }
pictureBox1.Image = bmTile1;
 
Share this answer
 
Comments
saifullahiit 10-Feb-12 9:01am    
it only draw one line. i want to draw 10 line. can you tell me how is it possible?
OriginalGriff 10-Feb-12 9:43am    
You could call it ten times, with different values...
First of all, I don't see where are you drawing on the image.

You would draw if you did
C#
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(myBitmap);
graphic.DrawLine(/*...*/);
graphic.FillRectangle(/*...*/);


See: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

Besides, are you sure you need PictureBox. This control is often abused. It is only good if you put some static image in it, well, maybe change is on some event, but not for anything interactive, dynamic, animated, etc.

Please consider my advice where I'll show what to do instead.
Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^].

See also:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900