469,313 Members | 2,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,313 developers. It's quick & easy.

Save lines drawn in the picturebox as an lmage

Have used DrawLine() method to draw some lines in the picturebox (sort
of a barcode) in the picturebox paint event.
This diagram has to be saved as an image in bmp or tiff format.
But the problem is that these lines are not recognized as the image of
the picturebox.
It shows picturebox.image = nothing.

How do we convert these lines drawn as the image of the picturebox so
that it can be saved.

Thanks for any help.

Jan 20 '06 #1
4 9813
Hi, you need to draw to a bitmap's Graphics object:

Dim b As Bitmap = New Bitmap(100,100)
Dim g As Graphics = Graphics.FromImage(b)

g.DrawLine(Pens.Black, 5,5,50,5)
g.Dispose()

picturebox1.image = b
b.Save(...)

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Yash" <de*********@gmail.com> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com...
Have used DrawLine() method to draw some lines in the picturebox (sort
of a barcode) in the picturebox paint event.
This diagram has to be saved as an image in bmp or tiff format.
But the problem is that these lines are not recognized as the image of
the picturebox.
It shows picturebox.image = nothing.

How do we convert these lines drawn as the image of the picturebox so
that it can be saved.

Thanks for any help.

Jan 20 '06 #2

Thanks Peter
The saving part is working perfectly.
The preview also shows the image properly.

But there's another problem
The image contains Black and colored lines.
So if we open this image in Paint to change some colors,
the background shown is black -- which hides the black lines totally.

I tried Bitmap.MakeTransparent but still the same.
The image is transparent but still the background is black.
Is this a .NET problem or Paint problem.
Any idea how to change this.
Peter Proost wrote:
Hi, you need to draw to a bitmap's Graphics object:

Dim b As Bitmap = New Bitmap(100,100)
Dim g As Graphics = Graphics.FromImage(b)

g.DrawLine(Pens.Black, 5,5,50,5)
g.Dispose()

picturebox1.image = b
b.Save(...)

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Yash" <de*********@gmail.com> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com...
Have used DrawLine() method to draw some lines in the picturebox (sort
of a barcode) in the picturebox paint event.
This diagram has to be saved as an image in bmp or tiff format.
But the problem is that these lines are not recognized as the image of
the picturebox.
It shows picturebox.image = nothing.

How do we convert these lines drawn as the image of the picturebox so
that it can be saved.

Thanks for any help.


Jan 20 '06 #3
Hi,

add
g.Clear(Color.White) before g.DrawLine(Pens.Black, 5,5,50,5)
this clears the drawing surface and should do the trick for you

Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Yash" <de*********@gmail.com> schreef in bericht
news:11**********************@o13g2000cwo.googlegr oups.com...

Thanks Peter
The saving part is working perfectly.
The preview also shows the image properly.

But there's another problem
The image contains Black and colored lines.
So if we open this image in Paint to change some colors,
the background shown is black -- which hides the black lines totally.

I tried Bitmap.MakeTransparent but still the same.
The image is transparent but still the background is black.
Is this a .NET problem or Paint problem.
Any idea how to change this.
Peter Proost wrote:
Hi, you need to draw to a bitmap's Graphics object:

Dim b As Bitmap = New Bitmap(100,100)
Dim g As Graphics = Graphics.FromImage(b)

g.DrawLine(Pens.Black, 5,5,50,5)
g.Dispose()

picturebox1.image = b
b.Save(...)

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"Yash" <de*********@gmail.com> schreef in bericht
news:11*********************@f14g2000cwb.googlegro ups.com...
Have used DrawLine() method to draw some lines in the picturebox (sort
of a barcode) in the picturebox paint event.
This diagram has to be saved as an image in bmp or tiff format.
But the problem is that these lines are not recognized as the image of
the picturebox.
It shows picturebox.image = nothing.

How do we convert these lines drawn as the image of the picturebox so
that it can be saved.

Thanks for any help.

Jan 20 '06 #4
"Yash" <de*********@gmail.com> schrieb:
Have used DrawLine() method to draw some lines in the picturebox (sort
of a barcode) in the picturebox paint event.
This diagram has to be saved as an image in bmp or tiff format.


<URL:http://www.dotnetrix.co.uk/misc.html>
-> "Save the Image currently displayed in a PictureBox."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Pavan Arise | last post: by
2 posts views Thread by Tomomichi Amano | last post: by
5 posts views Thread by Brian | last post: by
12 posts views Thread by yaya via DotNetMonster.com | last post: by
9 posts views Thread by davetelling | last post: by
12 posts views Thread by Lee | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.