I have used gdi to draw image on picturebox, now i want save the image on file. How to make it? :eek2:
Printable View
I have used gdi to draw image on picturebox, now i want save the image on file. How to make it? :eek2:
Picturebox1.Image.Save(filename)
Picturebox1.Image.Save(filename)
Error!!!
Error!!! isn't too helpful in helping you. What is the error?
Bill
If i copy the picturebox.image to another the picturebox2.image is null!
Why?
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
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.
So you are trying to load icon pictures to a toolbar? Why can't you just use the image property of the ToolbarItems
Bill
toolbar is the name of the picturebox
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
Ok but i don't have the image, i'm drawing the image on the picturebox. and later i want save this file image.
http://www.vbforums.com/
http://www.vbforums.com/
I made this.
http://www.vbforums.com/http://www.vbforums.com/
and now i want save this file ok.
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
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.
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)