|
-
Feb 5th, 2006, 10:08 AM
#1
Thread Starter
Junior Member
Save draw to file
I have used gdi to draw image on picturebox, now i want save the image on file. How to make it?
-
Feb 5th, 2006, 10:10 AM
#2
Re: Save draw to file
Picturebox1.Image.Save(filename)
-
Feb 5th, 2006, 10:20 AM
#3
Thread Starter
Junior Member
Re: Save draw to file
Picturebox1.Image.Save(filename)
Error!!!
-
Feb 5th, 2006, 10:55 AM
#4
Re: Save draw to file
Error!!! isn't too helpful in helping you. What is the error?
Bill
-
Feb 5th, 2006, 11:04 AM
#5
Thread Starter
Junior Member
Re: Save draw to file
If i copy the picturebox.image to another the picturebox2.image is null!
Why?
-
Feb 5th, 2006, 11:07 AM
#6
Re: Save draw to file
What is the code you are using to perform the drawing? my guess is that you are using the CreateGraphics method, and yes, that will put GDI+ pictures on the picturebox, but it will forget about them right away. For example, if after you draw the images, you minimize and then restore the form, is the picture still there? if it's not, then that means saving that image isn't going to do much for you, you would have to do your drawing onto a bitmap object, instead of just on the screen.
Bill
-
Feb 5th, 2006, 11:12 AM
#7
Thread Starter
Junior Member
Re: Save draw to file
With openfile
Dim myGraphics As Graphics
.CheckFileExists = True
.ShowReadOnly = False
.Filter = "Tutti i file immagine(*.png)|*.png;"
.FilterIndex = 2
If .ShowDialog = DialogResult.OK Then
Dim g As Graphics = Toolbar.CreateGraphics
Dim smallImage As Image = Image.FromFile(.FileName)
g.DrawImage(smallImage, 0, 0)
g.Dispose()
End If
End With
This code is used for 14 image.
-
Feb 5th, 2006, 11:33 AM
#8
Re: Save draw to file
So you are trying to load icon pictures to a toolbar? Why can't you just use the image property of the ToolbarItems
Bill
-
Feb 5th, 2006, 11:36 AM
#9
Thread Starter
Junior Member
Re: Save draw to file
toolbar is the name of the picturebox
-
Feb 5th, 2006, 11:45 AM
#10
Re: Save draw to file
Hmm, I still don't get why you're using GDI+ for this, when the picturebox has the image property.. But, I'll assume you have a reason. here's one method.
VB Code:
Dim gr As Graphics 'Make a new graphics object
Dim Bm As New Bitmap(PictureBox1.Width, PictureBox1.Height) 'Create a memory bitmap object the size of your picturebox
gr = Graphics.FromImage(Bm) 'Assing the graphics object to the memory bitmap
gr.DrawImage(Image.FromFile("z:\mybcd.gif"), 0, 0) 'Draw the image to the memory bitmap object.
PictureBox1.Image = Bm 'Set the picture to the memory bitmap
PictureBox1.Image.Save("Z:\mybcd.bmp", Imaging.ImageFormat.Bmp) 'Save it as a bitmap file (lots more formats in Imaging.ImageFormat)
gr.Dispose() 'Always dispose graphics objects.
Bill
-
Feb 5th, 2006, 11:50 AM
#11
Thread Starter
Junior Member
-
Feb 5th, 2006, 12:12 PM
#12
Re: Save draw to file
This is a duplicate thread of the one that lots of people answered this question in.
http://www.vbforums.com/showthread.php?t=385477
However, I'll make one final stab at it, modifying my code above.
VB Code:
Dim gr As Graphics 'Make a new graphics object
Dim Bm As Image = Image.FromFile("firstimage.png")
Dim Bm2 As Image = Image.FromFile("secondimage.png")
Dim mergedbitmap As New Bitmap(Bm.Width + Bm2.Width, Bm.Height) 'Create a memory bitmap object the size of your two images
gr = Graphics.FromImage(mergedbitmap) 'Assing the graphics object to the memory bitmap
gr.DrawImage(Bm, 0, 0) 'Draw the first image to the memory bitmap object.
gr.DrawImage(Bm2, Bm.Width, 0) 'Draw the second image to the memory bitmap object.
PictureBox1.Image = mergedbitmap 'Set the picture to the memory bitmap
PictureBox1.Image.Save("Z:\merged.ping", Imaging.ImageFormat.Png) 'Save it as a png file
gr.Dispose() 'Always dispose graphics objects.
In the future, it's considered rude to start a thread about something when lots of people have given you advice already about it.
Bill
-
Feb 5th, 2006, 12:16 PM
#13
Thread Starter
Junior Member
Re: Save draw to file
ok but if I want to load the images with openfile dialog as I make to join the images? I then put single every memory path and them markup to the end.
-
Feb 5th, 2006, 12:30 PM
#14
Thread Starter
Junior Member
Re: Save draw to file
Ok i'm used a listbox to save the path of file and later i recall the file to draw te image and save the new bitmap.
Dim Bm As Image = Image.FromFile(list.Items(0).ToString)
Dim Bm2 As Image = Image.FromFile(list.Items(1).ToString)
Dim Bm3 As Image = Image.FromFile(list.Items(2).ToString)
Dim Bm4 As Image = Image.FromFile(list.Items(3).ToString)
Dim Bm5 As Image = Image.FromFile(list.Items(4).ToString)
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
|