473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 10204
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pavan Arise | last post by:
Dear all.. I have a picturebox filled on a form. The picturebox has some graphics displayed on it.I was trying to save the picturebox, but continuesly failed to do so. I am clueless of why it is...
2
by: Michael Lehar | last post by:
Hallo I have a pictureBox with a picture loaded from file, then I draw some lines on the picture, and then I want to save the new picture. Befor I can draw lines I have to create a Graphics...
2
by: Tomomichi Amano | last post by:
Hello How can I delete (clear) lines that were made useing Graphics.DrawLine() ? Thanks in advance! Have a nice day!
5
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the...
12
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error...
0
by: melanieab | last post by:
Hi, I'm trying to get a clock to run. What I have is this: private void toggleOnOff_Click(object sender, System.EventArgs e){} which looks to see which picture to load in a picturebox. It...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
12
by: Lee | last post by:
I have the following code using System; using System.Windows.Forms; using System.Drawing; using System.Collections; namespace FINN {
10
by: eddie tan | last post by:
Hi, I have a picturebox with graphics drawn from different objects. In one object I used Pen P1; P1 = new Pen(Color.Blue, 3); Graphics g = null; g = Graphics.FromImage(image.Image);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.