471,058 Members | 990 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,058 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 10616
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Carl | last post: by
12 posts views Thread by yaya via DotNetMonster.com | last post: by
2 posts views Thread by kalp suth via DotNetMonster.com | last post: by
5 posts views Thread by Steve Marshall | last post: by
1 post views Thread by The Confessor | last post: by
8 posts views Thread by vicky87.eie | last post: by
reply views Thread by leo001 | last post: by

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.