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. 5 2475
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.net/gdiplus_faq.htm>
Read and be enlightened :)
--
Larry Lard
Replies to group please
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*******@hotmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.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.net/gdiplus_faq.htm>
Read and be enlightened :)
-- Larry Lard Replies to group please
It's quite easy really:
Public Sub CreateAndSave()
Dim theBitmap As New Bitmap(400, 400)
Dim theGraphics As Graphics
theGraphics = Graphics.FromImage(theBitmap)
theGraphics.FillEllipse(System.Drawing.Brushes.Blu e, New Rectangle(0, 0,
100, 100))
theBitmap.Save("c:\theFile.bmp", System.Drawing.Imaging.ImageFormat.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*******@hotmail.com> wrote in message news:11*********************@g47g2000cwa.googlegro ups.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.net/gdiplus_faq.htm>
Read and be enlightened :)
-- Larry Lard Replies to group please
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
programmatically, 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.PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.AliceBlue)
g.DrawRectangle(Pens.Bisque, 30, 60, 40, 50)
g.FillRectangle(Brushes.LightGreen, 100, 40, 10, 60)
g.DrawString("some text", New Font(FontFamily.GenericSansSerif,
12, FontStyle.Bold, GraphicsUnit.Point), Brushes.Red, 50, 50)
bmp.Save("c:\temp\mynewimage.bmp", ImageFormat.Bmp)
Things to note:
- Bitmap is a subclass of Image, so look in both classes' docs for
interesting stuff
- Graphics.FromImage 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*******@hotmail.com> wrote in message news:11*********************@g47g2000cwa.googlegro ups.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.net/gdiplus_faq.htm>
Read and be enlightened :)
-- Larry Lard Replies to group please
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*******@hotmail.com> wrote in message news:11*********************@g47g2000cwa.googlegro ups.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.net/gdiplus_faq.htm>
Read and be enlightened :)
-- Larry Lard Replies to group please
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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,...
| |
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")
|
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...
|
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...
|
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...
|
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...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |