[RESOLVED] Saving image from the picturebox
Hello all,
i have a picturebox control where the user can draw something. There is a save button which should save the image drawn in the picturebox. This is the code for the save button. I am using common dialog box and using save dialog box available from it. Also, i have used the SavePicture method just like Loadpicture method. But i am getting runtime error...
Private Sub save_Click()
Dim FileName As String
cdlg.DefaultExt = "jpg"
cdlg.FileName = "untitled.jpg"
cdlg.Filter = "JPEG files (*.jpg)|*.JPG"
cdlg.InitDir = App.Path
cdlg.DialogTitle = "File save"
cdlg.ShowSave
FileName = cdlg.FileName
SavePicture(picCanvas.Picture, FileName) = picCanvas.Picture
End Sub
Re: Saving image from the picturebox
change this line
Code:
SavePicture picCanvas.Picture, FileName
Re: Saving image from the picturebox
Quote:
Originally Posted by chunks
change this line
Code:
SavePicture picCanvas.Picture, FileName
Actually, since users are drawing on it, you should save the .Image not the .Picture. The contents will be saved as BMP.
Code:
SavePicture picCanvas.Image, FileName
rani_techie,
VB does not save anything in JPG format. If you want JPG format, you will need to use GDI+ or a DLL that will convert the image to JPG.
Re: Saving image from the picturebox
This is somewhat advanced, but hopefully this will help you in saving a picture in JPEG format.
http://www.tek-tips.com/viewthread.cfm?qid=760856
1 Attachment(s)
Re: Saving image from the picturebox
I posted this in a thread a few days ago, thought it was the same one.
Just save and convert!
Code:
Option Explicit
' NOTE: You must save the file in .BMP format before converting it.
Private Declare Function BmpToJpeg Lib "Bmp2Jpeg.dll" (ByVal BmpFilename As String, ByVal JpegFilename As String, ByVal CompressQuality As Integer) As Integer
Private Sub cmdLoad_Click()
Dim filename As String
On Error Resume Next
'Set the filter to bitmap pictures
dlg.Filter = "Bitmap Files | *.bmp"
dlg.filename = ""
dlg.ShowOpen
'Get the file name
filename = dlg.filename
'Load the picture
picMain.Picture = LoadPicture(filename)
End Sub
'For saving into jpg format you must have
'the Bmp2Jpeg.dll file in your windows folder
Private Sub cmdSave_Click()
Dim filename As String
On Error Resume Next
'Set the filter to JPEG files
dlg.Filter = "JPEG files | *.jpg"
dlg.filename = ""
dlg.ShowOpen
'Get the file name without the ".jpg"
filename = Left(dlg.filename, Len(dlg.filename) - 4)
'Saving the file as Bitmap
SavePicture picMain.Picture, filename & ".bmp"
'Change the bitmap file to the jpg file with the Bmp2Jpg.dll
'100 is the Compress Quality
BmpToJpeg filename & ".bmp", filename & ".jpg", 100
'Deleting the bitmap file
Kill filename & ".bmp"
End Sub
I've included the .dll so you don't have to hunt it down.