473,583 Members | 3,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving drawing graphics

Hi all,

I am converting an app which used a picturebox to draw graphs etc onto, then
saved them to a file. I can certainly draw things onto a picturbox in
VB.NET, but how do I save them to a file? I've looked at Bitmap objects,
which support saving, but can't see a way to grab what I have drawn and make
a bitmap from it, or whatever. Anybody done this?

Thanks for any suggestions

Remove numerals from e-mail address if e-mailing.
Nov 21 '05 #1
5 2515

Steve Marshall wrote:
Hi all,

I am converting an app which used a picturebox to draw graphs etc onto, then
saved them to a file. I can certainly draw things onto a picturbox in
VB.NET, but how do I save them to a file? I've looked at Bitmap objects,
which support saving, but can't see a way to grab what I have drawn and make
a bitmap from it, or whatever. Anybody done this?


<http://www.bobpowell.n et/gdiplus_faq.htm >

Read and be enlightened :)

--
Larry Lard
Replies to group please

Nov 21 '05 #2
Thanks for that Larry. I had actually found that page myself. But I'm
still not completely enlightened...

OK, I get that a PictureBox is not the "right" way to draw things in VB.
But it's still not clear to me what IS the right way! All I need to do is
draw a grid and a few lines, plus a bit of text, then save it to a file. It
ain't rocket science, which is why I was using a simple PictureBox in VB6,
which of course worked beautifully. I haven't looked at every article on
the page, but thus far have not ofund a "recipe" for simple drawing and
saving to file.

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...

Steve Marshall wrote:
Hi all,

I am converting an app which used a picturebox to draw graphs etc onto,
then
saved them to a file. I can certainly draw things onto a picturbox in
VB.NET, but how do I save them to a file? I've looked at Bitmap objects,
which support saving, but can't see a way to grab what I have drawn and
make
a bitmap from it, or whatever. Anybody done this?


<http://www.bobpowell.n et/gdiplus_faq.htm >

Read and be enlightened :)

--
Larry Lard
Replies to group please

Nov 21 '05 #3
It's quite easy really:

Public Sub CreateAndSave()

Dim theBitmap As New Bitmap(400, 400)
Dim theGraphics As Graphics

theGraphics = Graphics.FromIm age(theBitmap)
theGraphics.Fil lEllipse(System .Drawing.Brushe s.Blue, New Rectangle(0, 0,
100, 100))

theBitmap.Save( "c:\theFile.bmp ", System.Drawing. Imaging.ImageFo rmat.Bmp)

End Sub

Dim theGraphics as Graphics = PictureBox1.
"Steve Marshall" <st****@westnet .net.au> wrote in message
news:11******** *******@quartz. westnet.net.au. ..
Thanks for that Larry. I had actually found that page myself. But I'm
still not completely enlightened...

OK, I get that a PictureBox is not the "right" way to draw things in VB.
But it's still not clear to me what IS the right way! All I need to do is
draw a grid and a few lines, plus a bit of text, then save it to a file.
It ain't rocket science, which is why I was using a simple PictureBox in
VB6, which of course worked beautifully. I haven't looked at every
article on the page, but thus far have not ofund a "recipe" for simple
drawing and saving to file.

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...

Steve Marshall wrote:
Hi all,

I am converting an app which used a picturebox to draw graphs etc onto,
then
saved them to a file. I can certainly draw things onto a picturbox in
VB.NET, but how do I save them to a file? I've looked at Bitmap
objects,
which support saving, but can't see a way to grab what I have drawn and
make
a bitmap from it, or whatever. Anybody done this?


<http://www.bobpowell.n et/gdiplus_faq.htm >

Read and be enlightened :)

--
Larry Lard
Replies to group please


Nov 21 '05 #4

Steve Marshall wrote:
Thanks for that Larry. I had actually found that page myself.
So much for my easy way out :)
But I'm
still not completely enlightened...

OK, I get that a PictureBox is not the "right" way to draw things in VB.
But it's still not clear to me what IS the right way! All I need to do is
draw a grid and a few lines, plus a bit of text, then save it to a file.
If by this you mean that you are doing things entirely
programmaticall y, with no user interaction, then yes, a PictureBox is
inappropriate. VB6 needed to do things this way because it had no way
of manipulating a conceptual 'image' - the only thing if could draw on
was a PictureBox. However, with .NET, we have a formal Image and a
Graphics, and all a PictureBox is is a way of *displaying to the user*
an Image. If we don't need to involve the user, we don't need a
PictureBox at all.

Once you have these concepts straight it's just a matter of finding the
framework functionality that does what you want.

It
ain't rocket science, which is why I was using a simple PictureBox in VB6,
which of course worked beautifully. I haven't looked at every article on
the page, but thus far have not ofund a "recipe" for simple drawing and
saving to file.
Imports System.Drawing
Imports System.Drawing. Imaging

' in a procedure now:
Dim bmp As Bitmap = New Bitmap(128, 128,
Imaging.PixelFo rmat.Format24bp pRgb)

Dim g As Graphics = Graphics.FromIm age(bmp)

g.Clear(Color.A liceBlue)

g.DrawRectangle (Pens.Bisque, 30, 60, 40, 50)
g.FillRectangle (Brushes.LightG reen, 100, 40, 10, 60)
g.DrawString("s ome text", New Font(FontFamily .GenericSansSer if,
12, FontStyle.Bold, GraphicsUnit.Po int), Brushes.Red, 50, 50)

bmp.Save("c:\te mp\mynewimage.b mp", ImageFormat.Bmp )

Things to note:

- Bitmap is a subclass of Image, so look in both classes' docs for
interesting stuff
- Graphics.FromIm age is obviously the key method for obtaining a
drawing surface (a Graphics) for a given Image object
- Note that there is no Form in sight here - this code would work just
as well in a Class Library as in a Windows Forms app

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...

Steve Marshall wrote:
Hi all,

I am converting an app which used a picturebox to draw graphs etc onto,
then
saved them to a file. I can certainly draw things onto a picturbox in
VB.NET, but how do I save them to a file? I've looked at Bitmap objects,
which support saving, but can't see a way to grab what I have drawn and
make
a bitmap from it, or whatever. Anybody done this?


<http://www.bobpowell.n et/gdiplus_faq.htm >

Read and be enlightened :)

--
Larry Lard
Replies to group please


Nov 21 '05 #5
Many thanks for the responses. I'm sure they will set me on the path of
drawing righteousness!

Cheers

"Steve Marshall" <st****@westnet .net.au> wrote in message
news:11******** *******@quartz. westnet.net.au. ..
Thanks for that Larry. I had actually found that page myself. But I'm
still not completely enlightened...

OK, I get that a PictureBox is not the "right" way to draw things in VB.
But it's still not clear to me what IS the right way! All I need to do is
draw a grid and a few lines, plus a bit of text, then save it to a file.
It ain't rocket science, which is why I was using a simple PictureBox in
VB6, which of course worked beautifully. I haven't looked at every
article on the page, but thus far have not ofund a "recipe" for simple
drawing and saving to file.

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...

Steve Marshall wrote:
Hi all,

I am converting an app which used a picturebox to draw graphs etc onto,
then
saved them to a file. I can certainly draw things onto a picturbox in
VB.NET, but how do I save them to a file? I've looked at Bitmap
objects,
which support saving, but can't see a way to grab what I have drawn and
make
a bitmap from it, or whatever. Anybody done this?


<http://www.bobpowell.n et/gdiplus_faq.htm >

Read and be enlightened :)

--
Larry Lard
Replies to group please


Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
20279
by: Vin | last post by:
Hi, I am using the following code to draw whatever the user draws using x,y. // draws lines directly on a winform. CreateGraphics().DrawLine(APen, x, y, OldX, OldY); Now how do I save the drawing on to a bmp file on my harddisk? C# code in this regard would be very helpful. I tried all forums but invain.
4
4244
by: CodeRazor | last post by:
I'm unfamiliar with image manipulation using c#. How can i resize a jpg that currently exists in a file and save it resized as a new file. The examples i've found have been a bit misleading for my particular requirements.
4
2283
by: melanieab | last post by:
Hi, I'm trying to save a bitmap file so I can print it later. I have Image.Save("sImage.bmp",System.Drawing.Imaging.ImageFormat.Bmp); The file sImage.bmp shows up in the bin\debug folder but when I try to print it (or open it), it's completely black. I know Image is the correct picture because when I immediately print it, it works. What...
7
8712
by: Marc Pelletier | last post by:
Hello all, I have a class which includes a method to create a chart. I want to be able to call this method from asp.net code as well as windows application code, so I have sketched it out as returning a bitmap instance. In my asp.net code I think I should call this method to return a bitmap and then somehow stream it using the response...
0
1112
by: monfu | last post by:
Dear all I have the following code:- System.Drawing.Image src_image = System.Drawing.Image.FromStream(imgStream); Bitmap bitmap = new Bitmap(image_width, image_height, src_image.PixelFormat); Graphics new_g = Graphics.FromImage(bitmap);
8
10775
by: nobody | last post by:
How do I save a PictureBox bitmap with changes drawn on the bitmap? This doesn't do it: PictureBox1.Image.Save("key30.bmp")
5
4723
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the date stamped on the lower right part of the picture. (I'm not an advanced programmer so my code may not be 100% efficient - sorry, I'm still...
1
1494
by: NutsAboutVB | last post by:
Hello, I am a VB.NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File --> Save) in MS Photo Editor, the file is automatically shrunk in size to 81 KB's. When doing the same thing in MS Paint, the file is shrunk to 54...
8
2238
by: vicky87.eie | last post by:
I used a picture box to draw lines and rectangle using its graphics object in paint event. Now i need to save those lines i have drawn and print them. I need to know how to save them. I tried image.save. But i didn't work...
0
7824
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8176
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8321
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7931
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5699
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1426
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1154
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.