Home All Groups Group Topic Archive Search About

Save lines drawn in the picturebox as an lmage

Author
20 Jan 2006 6:46 AM
Yash
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.

Author
20 Jan 2006 8:17 AM
Peter Proost
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)

Show quoteHide quote
"Yash" <develope***@gmail.com> schreef in bericht
news:1137739561.357485.11550@f14g2000cwb.googlegroups.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.
>
Author
20 Jan 2006 12:45 PM
Yash
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:
Show quoteHide quote
> 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" <develope***@gmail.com> schreef in bericht
> news:1137739561.357485.11550@f14g2000cwb.googlegroups.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.
> >
Author
20 Jan 2006 1:10 PM
Peter Proost
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)

Show quoteHide quote
"Yash" <develope***@gmail.com> schreef in bericht
news:1137761134.892145.119190@o13g2000cwo.googlegroups.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" <develope***@gmail.com> schreef in bericht
> > news:1137739561.357485.11550@f14g2000cwb.googlegroups.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.
> > >
>
Author
20 Jan 2006 3:25 PM
Herfried K. Wagner [MVP]
"Yash" <develope***@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/>