|
-
Jun 4th, 2011, 02:06 AM
#1
Thread Starter
Fanatic Member
Save drawing from PictureBox
Hey there,
I'm trying to save the lines I drew in a PictureBox as a bitmap, but it just returns blank images...
This is the code I have now:
vb Code:
'Draw a grid on PictureBox named draw
For x As Integer = 0 To bWidth
For y As Integer = 0 To bHeight
draw.CreateGraphics.DrawLine(Pens.Black, New Point(xStart + x * bScale, yStart), New Point(xStart + x * bScale, yStart + ySize))
draw.CreateGraphics.DrawLine(Pens.Black, New Point(xStart, yStart + y * bScale), New Point(xStart + xSize, yStart + y * bScale))
Next
Next
'Save as BMP-file
Dim bmp As New Bitmap(draw.Width, draw.Height)
draw.DrawToBitmap(bmp, New Rectangle(0, 0, draw.Width, draw.Height))
bmp.Save("D:\output.png", Imaging.ImageFormat.Png)
bmp.Dispose()
The file output.png in now a blank image, the size of the PictureBox. If I try to save the entire form with Me.DrawToBitmap(), I get the form itself but the PictureBox is blank, while the grid is visible on screen.
WHAT DO?!
Thanks for your help,
Alexander.
Last edited by arsmakman; Jun 4th, 2011 at 03:50 AM.
Reason: Issue resolved
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jun 4th, 2011, 02:40 AM
#2
Re: Save drawing from PictureBox
Follow the CodeBank link in my signature and check out my Simple Drawing thread. It shows you how to draw on a PictureBox and then transfer that drawing to the Image in a the PictureBox. You can then just Save that Image.
-
Jun 4th, 2011, 03:50 AM
#3
Thread Starter
Fanatic Member
Re: Save drawing from PictureBox
That got it working! The *working* code I have now is:
vb Code:
'Draw grid
Using g As Graphics = Graphics.FromImage(draw.Image)
For x As Integer = 0 To bWidth
For y As Integer = 0 To bHeight
g.DrawLine(Pens.Black, New Point(xStart + x * bScale, yStart), New Point(xStart + x * bScale, yStart + ySize))
g.DrawLine(Pens.Black, New Point(xStart, yStart + y * bScale), New Point(xStart + xSize, yStart + y * bScale))
Next
Next
End Using
'Save as PNG-file
Dim bmp As New Bitmap(draw.Width, draw.Height)
draw.DrawToBitmap(bmp, New Rectangle(0, 0, draw.Width, draw.Height))
bmp.Save("D:\output.png", Imaging.ImageFormat.Png)
bmp.Dispose()
Thanks for your help!
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Jul 10th, 2011, 06:38 AM
#4
New Member
Re: Save drawing from PictureBox
Can you mail me the full code. i am new with vb.
Thanks
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
|