472,951 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Saving a PictureBox bitmap with changes drawn...


How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")

Nov 20 '05 #1
8 10729
Hi,

Dim fs As New System.IO.FileStream("c:\key30.bmp", IO.FileMode.Open)
Dim bm As New Bitmap(fs)

fs.Close()

Dim g As Graphics = Graphics.FromImage(bm)
g.FillEllipse(Brushes.Red, 10, 10, 100, 100)

g.Dispose()

bm.Save("C:\key30.bmp", Imaging.ImageFormat.Bmp)

Ken
-------------------------
"nobody" <no*****@nonenetcom.net> wrote in message
news:ZA******************@newssvr31.news.prodigy.c om...

How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")

Nov 20 '05 #2
"nobody" <no*****@nonenetcom.net> schrieb

How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")


Do you really paint on the bitmap assigned to the Picturebox' Image property
or on the Picturebox?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Armin Zingler wrote:
"nobody" <no*****@nonenetcom.net> schrieb
How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")

Do you really paint on the bitmap assigned to the Picturebox' Image property
or on the Picturebox?


Here's what I got....

Dim GraphicsFun As System.Drawing.Graphics
GraphicsFun = PictureBox1.CreateGraphics
Dim aFont As New System.Drawing.Font("MS Sans Serif", 11, _ FontStyle.Bold)
Dim drawBrush As New _ System.Drawing.SolidBrush(System.Drawing.Color.Bla ck)
Dim drawFormat As New System.Drawing.StringFormat

GraphicsFun.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)

'This draws on the picture, but when saved, it doesn't
'save what is drawn, just saves the original loaded from file.

Nov 20 '05 #4
"nobody" <no*****@nonenetcom.net> schrieb
Armin Zingler wrote:
"nobody" <no*****@nonenetcom.net> schrieb
How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")

Do you really paint on the bitmap assigned to the Picturebox' Image
property or on the Picturebox?


Here's what I got....

Dim GraphicsFun As System.Drawing.Graphics
GraphicsFun = PictureBox1.CreateGraphics
Dim aFont As New System.Drawing.Font("MS Sans Serif", 11, _
FontStyle.Bold)
Dim drawBrush As New _
System.Drawing.SolidBrush(System.Drawing.Color.Bla ck)
Dim drawFormat As New System.Drawing.StringFormat

GraphicsFun.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)

'This draws on the picture, but when saved, it doesn't
'save what is drawn, just saves the original loaded from file.


You are directly drawing on the Picturebox, not on the image assigned to the
Image property. To draw on the image:

dim g as graphics
g = graphics.fromimage(PictureBox1.image)
g.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)
g.dispose

If you didn't assign an image to the Image property, you must do it before.

--
Armin

Nov 20 '05 #5
Armin Zingler wrote:
"nobody" <no*****@nonenetcom.net> schrieb
Armin Zingler wrote:

"nobody" <no*****@nonenetcom.net> schrieb
How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")
Do you really paint on the bitmap assigned to the Picturebox' Image
property or on the Picturebox?


Here's what I got....

Dim GraphicsFun As System.Drawing.Graphics
GraphicsFun = PictureBox1.CreateGraphics
Dim aFont As New System.Drawing.Font("MS Sans Serif", 11, _
FontStyle.Bold)
Dim drawBrush As New _
System.Drawing.SolidBrush(System.Drawing.Color.B lack)
Dim drawFormat As New System.Drawing.StringFormat

GraphicsFun.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)

'This draws on the picture, but when saved, it doesn't
'save what is drawn, just saves the original loaded from file.

You are directly drawing on the Picturebox, not on the image assigned to the
Image property. To draw on the image:

dim g as graphics
g = graphics.fromimage(PictureBox1.image)
g.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)
g.dispose

If you didn't assign an image to the Image property, you must do it before.


I'm getting this error message below....

"An unhandled exception of type 'System.Exception' occurred in
system.drawing.dll
Additional information: A Graphics object cannot be created from an
image that has an indexed pixel format."


Nov 20 '05 #6
nobody wrote:
Armin Zingler wrote:
"nobody" <no*****@nonenetcom.net> schrieb
Armin Zingler wrote:
"nobody" <no*****@nonenetcom.net> schrieb
> How do I save a PictureBox bitmap with changes
> drawn on the bitmap?
> This doesn't do it:
> PictureBox1.Image.Save("key30.bmp")

Do you really paint on the bitmap assigned to the Picturebox' Image
property or on the Picturebox?
Here's what I got....

Dim GraphicsFun As System.Drawing.Graphics
GraphicsFun = PictureBox1.CreateGraphics
Dim aFont As New System.Drawing.Font("MS Sans Serif", 11, _
FontStyle.Bold)
Dim drawBrush As New _
System.Drawing.SolidBrush(System.Drawing.Color.Bla ck)
Dim drawFormat As New System.Drawing.StringFormat

GraphicsFun.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)

'This draws on the picture, but when saved, it doesn't
'save what is drawn, just saves the original loaded from file.


You are directly drawing on the Picturebox, not on the image assigned
to the
Image property. To draw on the image:

dim g as graphics
g = graphics.fromimage(PictureBox1.image)
g.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)
g.dispose

If you didn't assign an image to the Image property, you must do it
before.

I'm getting this error message below....

"An unhandled exception of type 'System.Exception' occurred in
system.drawing.dll
Additional information: A Graphics object cannot be created from an
image that has an indexed pixel format."


The line it goes to when the error occurs is....
g.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)
Nov 20 '05 #7
nobody wrote:

How do I save a PictureBox bitmap with changes
drawn on the bitmap?
This doesn't do it:
PictureBox1.Image.Save("key30.bmp")


Back to Delphi we go.
Nov 20 '05 #8
"nobody" <no*****@nonenetcom.net> schrieb
I'm getting this error message below....

"An unhandled exception of type 'System.Exception' occurred in
system.drawing.dll
Additional information: A Graphics object cannot be created from an
image that has an indexed pixel format."


The line it goes to when the error occurs is....
g.DrawString("E", aFont, drawBrush, 20, 31, drawFormat)


As the documentation of FromImage says, that certain formats are not
supported. Sorry. Do you have to have an indexed pixel format? Maybe you
could convert it to a Truecolor format to draw on it.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9

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

Similar topics

4
by: Carl | last post by:
In the application I'm writing, I'm modifying a windows bitmap using the circle and line methods. Once the changes have been made, I would like to save the bitmap with the changes. My problem is,...
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...
2
by: kalp suth via DotNetMonster.com | last post by:
I want to create arrows using lines on a picture in the picture box. On clicking the button "btnShowAll", the image is loaded and the lines drawn. "RGSShowAll()" calls "DrawObjs()" which does the...
5
by: Steve Marshall | last post by:
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...
4
by: Yash | last post by:
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...
1
by: The Confessor | last post by:
I'm trying to develop a graphically-simple, gameplay-complex RPG, and I decided to create a graphical Proof of Concept just to confirm that graphics would be... well, simple. Predictably,...
0
by: jamesjames | last post by:
Hello, could anyone tell me how to save a bitmap from picturebox.image as a 24bpprgb bitmap? picturebox.Image.Save(path, ImageFormat.Bmp) saves a 32bpprgb bitmap and Bitmap bmp =...
1
by: Nitin | last post by:
Hi! I've been trying to draw in a PictureBox and save the resulting image to a Bitmap object that I save to a file on disk. Unfortunately, I can't seem to get the elements that I'm drawing to...
8
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...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.