How To Store an Image From PictureBox To a directory Using VB.Net
In this VB.NET Tutorial we will see How To Upload A Picture To a PictureBox And Save The Same Picture In any Folder On The Computer With a Unique Name That We Will Create Using Date And Time On A Button Click Event In Visual Basic.Net Programming Language And Visual Studio Editor.
Project Source Code:
Imports System.Drawing.Imaging
Public Class save_image_from_picturebox
' upload image
Private Sub ButtonUpload_Click(sender As Object, e As EventArgs) Handles ButtonUpload.Click
Dim opf As New OpenFileDialog
' chose the images type
opf.Filter = "Choose Image(*.jpg;*.png;*.gif)|*.jpg;*.png;*.gif"
If opf.ShowDialog = DialogResult.OK Then
' get the image returned by OpenFileDialog
PictureBox1.Image = Image.FromFile(opf.FileName)
End If
End Sub
' button save
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
Dim svf As New SaveFileDialog()
' create a default name using date and time
Dim fname As String
fname = DateTime.Now.Year.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Hour.ToString() + "_" + DateTime.Now.Minute.ToString() + "_" + DateTime.Now.Second.ToString() + "." + ImageFormat.Jpeg.ToString()
svf.FileName = fname
If svf.ShowDialog() = Windows.Forms.DialogResult.OK Then
PictureBox1.Image.Save(svf.FileName)
End If
End Sub
End Class
OutPut:
Download Projects Source Code
1 comments:
commentsSir can you make a tutorial with jsp and servlet, thank you🙏
Reply