|
-
Jan 17th, 2003, 12:27 PM
#1
Thread Starter
Junior Member
How to save content in PictureBox?
I created one simple drawing program. Free hand drawn in the picturebox and wanted to save the content as image file
Can you teach me?
-
Jan 17th, 2003, 03:50 PM
#2
PowerPoster
Create a Bitmap object and store the picture in there. Then call the bitmaps save method to save the image to file.
There might even be a save method for the picturebox.....not sure though.
-
Jan 19th, 2003, 11:07 AM
#3
Thread Starter
Junior Member
i can't really understand what you mean...
let say... my picturebox is picDRAW, and i created a graphic... using brush to draw oon the picture box
then a cmdSAVE..
inside the cmdSAVE..what code should i write to save the content in picturebox as IMAGE file?
-
Jan 19th, 2003, 12:28 PM
#4
Sleep mode
as simple as this :
this code goes under you CmdSave Button :
VB Code:
PictureBox1.Image.Save("C:\MypicContent.bmp")
Ihopethiswhatyoumean!
-
Jan 19th, 2003, 12:31 PM
#5
PowerPoster
Code:
Dim bm As New Bitmap(PictureBox1.Image)
bm.Save(Application.StartupPath & "\myimage.jpg")
You might want to make sure the picturebox isn't empty first. It will throw an error if it is.
-
Jan 19th, 2003, 12:32 PM
#6
PowerPoster
Just a little late...lol.
-
Jan 20th, 2003, 10:49 AM
#7
Thread Starter
Junior Member
do u know how to save it by using savedialogbox?
-
Jan 20th, 2003, 11:00 AM
#8
PowerPoster
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim result As String
Dim bm As New Bitmap(PictureBox1.Image)
SaveFileDialog1.ShowDialog()
result = SaveFileDialog1.FileName
bm.Save(result)
End Sub
There is more you can do with the savefiledialog. Here is a link to start you out:
http://msdn.microsoft.com/library/de...classtopic.asp
-
Jan 20th, 2003, 11:31 AM
#9
Thread Starter
Junior Member
An unhandled exception of type 'System.NullReferenceException' occurred in system.drawing.dll
Additional information: Object reference not set to an instance of an object.
I got this error when i execute the program.it highlighted at
Dim bm As New Bitmap(PictureBox1.Image)
what's the problem
-
Jan 20th, 2003, 12:02 PM
#10
Sleep mode
Originally posted by maychia
An unhandled exception of type 'System.NullReferenceException' occurred in system.drawing.dll
Additional information: Object reference not set to an instance of an object.
I got this error when i execute the program.it highlighted at
Dim bm As New Bitmap(PictureBox1.Image)
what's the problem
just leave out the keyword New .
-
Jan 20th, 2003, 02:20 PM
#11
Originally posted by maychia
An unhandled exception of type 'System.NullReferenceException' occurred in system.drawing.dll
Additional information: Object reference not set to an instance of an object.
I got this error when i execute the program.it highlighted at
Dim bm As New Bitmap(PictureBox1.Image)
what's the problem
as he said you have to make sure the picturebox.image isnt = to Nothing
you could do something like this
bm= new bitmap (picbox.clientsize.width, picbox.clientsize.height)
I think it's a little different to pass the picturebox.image to the bitmap's constructor though, isnt it?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 21st, 2003, 07:11 AM
#12
Thread Starter
Junior Member
-
Jan 21st, 2003, 11:21 AM
#13
Sleep mode
strange behavior :
when I draw in the picturebox and any window covers the area of drawing then it's erased.in other word , the picturebox is not holding its content.First you have to fix this bug then I don't think you would face problems.
-
Jan 21st, 2003, 05:11 PM
#14
change mouse move to:
VB Code:
Private Sub picDraw_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDraw.MouseMove
If shouldpaint Then
Dim graphic As Graphics = createGraphicsEx(picDraw)
graphic.FillEllipse(New SolidBrush(_BrushColor), e.X, e.Y, _BrushSize, _BrushSize)
graphic.Dispose()
picDraw.Invalidate()
End If
End Sub
createGraphicsEx is a function I wrote:
VB Code:
' Returns a Graphics object to be used for drawing on the picturebox
Private Function createGraphicsEx(ByVal picbox As PictureBox) As Graphics
' If the picturebox's image is nothing, create a bitmap the same size as
' the picturebox
If picbox.Image Is Nothing Then
picbox.Image = New Bitmap(picbox.ClientSize.Width, picbox.ClientSize.Height)
Dim gr As Graphics = Graphics.FromImage(picbox.Image)
gr.Clear(picbox.BackColor)
Return gr
Else
Return Graphics.FromImage(picbox.Image)
End If
End Function
basically the only thing different is that instead of saying picbox.creategraphics, you are calling graphics.fromimage. That's all. I just made that a function so that you could use it again if you want. Also you shouldnt be drawing this with an ellipse. You should save the mouse position on each mousemove event and then draw a line from the last mouse position to the current mouse position.
You can save the picture now, and it wont disappear again
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 21st, 2003, 05:28 PM
#15
Sleep mode
I was wondering If I used Form1_Paint event , does this would solve it ?
-
Jan 21st, 2003, 05:40 PM
#16
Originally posted by pirate
I was wondering If I used Form1_Paint event , does this would solve it ?
if you want to use form_paint, then you have to know all the points needed to redraw the picture. OR you could draw the picture on a separate bitmap and repaint that every time on the paint event, which doesnt make any sense. This way you just draw the picture on the picturebox. When you use .CreateGraphics, it will not actually draw on the picturebox.Image object, that's why he couldnt save the picture
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 21st, 2003, 10:16 PM
#17
-
Jan 22nd, 2003, 11:32 AM
#18
Thread Starter
Junior Member
confusing~
MrPolite..then what should i code in cmdSave?
-
Jan 22nd, 2003, 09:19 PM
#19
Originally posted by maychia
confusing~
MrPolite..then what should i code in cmdSave?
aah sorry
VB Code:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
picDraw.Image.Save("C:\test.png", Imaging.ImageFormat.Png)
picDraw.Image.Save("C:\test.bmp")
End Sub
two examples I think it saves it as BMP by default
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 23rd, 2003, 11:15 AM
#20
Thread Starter
Junior Member
i though using SaveFileDialog to save????
-
Jan 23rd, 2003, 11:58 PM
#21
Originally posted by maychia
i though using SaveFileDialog to save????
eeh hellswraith already showed you. Here's another example:
VB Code:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim bmp As Bitmap = picDraw.Image
' Picturebox.Image is initially set to Nothing. You can set it to a new
' bitmap during startup if you want to aviod this
If bmp Is Nothing Then
MessageBox.Show("Image doesnt exist")
Else
SaveFileDialog1.Filter = "Bitmap (*.bmp)|*.bmp"
' Make sure the user pressed OK
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
bmp.Save(SaveFileDialog1.FileName)
End If
End If
End Sub
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 24th, 2003, 10:59 AM
#22
Thread Starter
Junior Member
-
Jan 26th, 2003, 10:56 AM
#23
Thread Starter
Junior Member
GREAT !!!!!!!! IT"S WORK!!!
SO weird....
Why I can't change the background color for the second time?
After the program start, I can change the background color if I draw
nothing on the picturebox, after I draw something there..
the background color not working?!~
How to clear all the content in the picturebox?
Previously, I using 'picDraw.invalidate'
now it's not working anymore
-
Jan 26th, 2003, 01:17 PM
#24
PowerPoster
I think for you to clear the image of the picture box, you just need to set it to nothing.
-
Jan 26th, 2003, 02:07 PM
#25
if you have an instance of the Graphics object, then you can do grahpic.clear([color])
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jan 27th, 2003, 11:57 AM
#26
Thread Starter
Junior Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|