To Download Source Code Click Here > Save image in MySettings.rar

  1. Open Visual Studio and Click on New Project window from template.
  2. Place Four buttons and a Picture box.
  3. Set Name Properties of :
    1. Button1 = "btnBrowse"
    2. Button2 = "btnSave"
    3. Button3 = "btnDelete"
    4. Button4 = "btnExit"
    5. Picturebox1 = "pctImage" 
    6. OpenFileDialog1 = "ofdImage"
    7. Form1 = "frmImageSave"
  4.Set Text Properties of :
    1. Button1 = "Browse"
    2. Button2 = "Save"
    3. Button3 = "Delete"
    4. Button4 = "Exit"
    5. Form1 = "Save Image"
  5.Goto Project Menu and Click on SaveImage in MySettings Properties.
  6.From the Left side Select Settings Tab
  7.Now Set the Name as Image.
  8.Select the Type and click on  Browse.
  9. Now a Window will open. In that click on System.Collections. Under that Click on ArrayList. 

10. Select Scope as User.
11. Set Value Field as Empty. I mean don't Enter any value.
12. Right Click on Form and click on View Code.
13. And Paste the following Code.

Imports System.IO

Public Class frmImageSave

    Private Sub frmImageSave_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not My.Settings.Image.Count = 0 Then
            Dim bytImage(My.Settings.Image.Count - 1) As Byte
            For index As Integer = 0 To My.Settings.Image.Count - 1
                bytImage(index) = My.Settings.Image.Item(index)
            Next
            Dim MS As New MemoryStream(bytImage)
            pctImage.Image = Image.FromStream(MS)
        Else
            pctImage.Image = Nothing
        End If
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        With ofdImage
            .InitialDirectory = "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\"
            .Filter = "JPEGs|*.jpg"
            .FilterIndex = 1
        End With
        If ofdImage.ShowDialog = Windows.Forms.DialogResult.OK Then
            If FormatNumber(FileLen(ofdImage.FileName) / 1024, 0) > 30 Then
                MessageBox.Show("Please Select Image of Size less then 30kbs", "Save Image", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
            With pctImage
                .Image = Image.FromFile(ofdImage.FileName)
                .SizeMode = PictureBoxSizeMode.StretchImage
            End With
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Dim MS As New MemoryStream
            pctImage.Image.Save(MS, Imaging.ImageFormat.Jpeg)
            Dim bytImage() As Byte = MS.GetBuffer
            For index As Integer = 0 To bytImage.Length - 1
                My.Settings.Image.Add(bytImage(index))
            Next
            My.Settings.Save()
            MessageBox.Show("Image Saved Successfully.", "Save Image", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message & " btnSave_Click")
        End Try
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        My.Settings.Image.Clear()
        My.Settings.Save()
        MessageBox.Show("Image Deleted Successfully.", "Save Image", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub

End Class

To Download Source Code Click Here > Save image in MySettings.rar