Private Sub button1_Click ( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles button1.Click Dim _bmp As Bitmap = New Bitmap(Me.pictureBox1.Image) Dim fep As frmExportPicture = New frmExportPicture(_bmp) fep.ShowDialog() End Sub Option Strict On   Imports System.Drawing Imports System.Drawing.Imaging   Public Class frmExportPicture Inherits System.Windows.Forms.Form   #Region " Windows Form Designer generated code "   Public Sub New(ByVal bmp As Bitmap)   MyBase.New()     'This call is required by the Windows Form Designer.   InitializeComponent()     'Add any initialization after the InitializeComponent() call   Me._bmp = bmp End Sub   'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)   If disposing Then     If Not (components Is Nothing) Then       components.Dispose()     End If   End If   MyBase.Dispose(disposing) End Sub   'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer   'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents panelExport As System.Windows.Forms.Panel Friend WithEvents groupBox2 As System.Windows.Forms.GroupBox Friend WithEvents checkBoxOpen As System.Windows.Forms.CheckBox Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox Friend WithEvents radioButtonColor As System.Windows.Forms.RadioButton Friend WithEvents radioButtonGS As System.Windows.Forms.RadioButton Friend WithEvents groupBoxExportFormat As System.Windows.Forms.GroupBox Friend WithEvents panel1 As System.Windows.Forms.Panel Friend WithEvents trackBar1 As System.Windows.Forms.TrackBar Friend WithEvents label7 As System.Windows.Forms.Label Friend WithEvents label3 As System.Windows.Forms.Label Friend WithEvents label4 As System.Windows.Forms.Label Friend WithEvents labelQuality As System.Windows.Forms.Label Friend WithEvents radioButtonJPEG As System.Windows.Forms.RadioButton Friend WithEvents radioButtonBMP As System.Windows.Forms.RadioButton Friend WithEvents groupBoxInfo As System.Windows.Forms.GroupBox Friend WithEvents label22 As System.Windows.Forms.Label Friend WithEvents label5 As System.Windows.Forms.Label Friend WithEvents label2 As System.Windows.Forms.Label Friend WithEvents labelVRes As System.Windows.Forms.Label Friend WithEvents labelHRes As System.Windows.Forms.Label Friend WithEvents labelHeight As System.Windows.Forms.Label Friend WithEvents labelWidth As System.Windows.Forms.Label Friend WithEvents label1 As System.Windows.Forms.Label Friend WithEvents groupBoxPreview As System.Windows.Forms.GroupBox Friend WithEvents pictureBox1 As System.Windows.Forms.PictureBox Friend WithEvents panelBottom As System.Windows.Forms.Panel Friend WithEvents button1 As System.Windows.Forms.Button Friend WithEvents buttonExport As System.Windows.Forms.Button Private Sub InitializeComponent()   Me.panelExport = New System.Windows.Forms.Panel()   Me.groupBox2 = New System.Windows.Forms.GroupBox()   Me.checkBoxOpen = New System.Windows.Forms.CheckBox()   Me.groupBox1 = New System.Windows.Forms.GroupBox()   Me.radioButtonColor = New System.Windows.Forms.RadioButton()   Me.radioButtonGS = New System.Windows.Forms.RadioButton()   Me.groupBoxExportFormat = New System.Windows.Forms.GroupBox()   Me.panel1 = New System.Windows.Forms.Panel()   Me.trackBar1 = New System.Windows.Forms.TrackBar()   Me.label7 = New System.Windows.Forms.Label()   Me.label3 = New System.Windows.Forms.Label()   Me.label4 = New System.Windows.Forms.Label()   Me.labelQuality = New System.Windows.Forms.Label()   Me.radioButtonJPEG = New System.Windows.Forms.RadioButton()   Me.radioButtonBMP = New System.Windows.Forms.RadioButton()   Me.groupBoxInfo = New System.Windows.Forms.GroupBox()   Me.label22 = New System.Windows.Forms.Label()   Me.label5 = New System.Windows.Forms.Label()   Me.label2 = New System.Windows.Forms.Label()   Me.labelVRes = New System.Windows.Forms.Label()   Me.labelHRes = New System.Windows.Forms.Label()   Me.labelHeight = New System.Windows.Forms.Label()   Me.labelWidth = New System.Windows.Forms.Label()   Me.label1 = New System.Windows.Forms.Label()   Me.groupBoxPreview = New System.Windows.Forms.GroupBox()   Me.pictureBox1 = New System.Windows.Forms.PictureBox()   Me.panelBottom = New System.Windows.Forms.Panel()   Me.button1 = New System.Windows.Forms.Button()   Me.buttonExport = New System.Windows.Forms.Button()   Me.panelExport.SuspendLayout()   Me.groupBox2.SuspendLayout()   Me.groupBox1.SuspendLayout()   Me.groupBoxExportFormat.SuspendLayout()   Me.panel1.SuspendLayout()   CType(Me.trackBar1, System.ComponentModel.ISupportInitialize).BeginInit()   Me.groupBoxInfo.SuspendLayout()   Me.groupBoxPreview.SuspendLayout()   Me.panelBottom.SuspendLayout()   Me.SuspendLayout()   '   'panelExport   '   Me.panelExport.Controls.Add(Me.groupBox2)   Me.panelExport.Controls.Add(Me.groupBox1)   Me.panelExport.Controls.Add(Me.groupBoxExportFormat)   Me.panelExport.Controls.Add(Me.groupBoxInfo)   Me.panelExport.Dock = System.Windows.Forms.DockStyle.Right   Me.panelExport.Location = New System.Drawing.Point(424, 0)   Me.panelExport.Name = "panelExport"   Me.panelExport.Size = New System.Drawing.Size(232, 414)   Me.panelExport.TabIndex = 15   '   'groupBox2   '   Me.groupBox2.Controls.Add(Me.checkBoxOpen)   Me.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.groupBox2.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.groupBox2.Location = New System.Drawing.Point(8, 320)   Me.groupBox2.Name = "groupBox2"   Me.groupBox2.Size = New System.Drawing.Size(216, 48)   Me.groupBox2.TabIndex = 13   Me.groupBox2.TabStop = False   Me.groupBox2.Text = "Options"   '   'checkBoxOpen   '   Me.checkBoxOpen.Checked = True   Me.checkBoxOpen.CheckState = System.Windows.Forms.CheckState.Checked   Me.checkBoxOpen.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.checkBoxOpen.Location = New System.Drawing.Point(8, 24)   Me.checkBoxOpen.Name = "checkBoxOpen"   Me.checkBoxOpen.Size = New System.Drawing.Size(184, 16)   Me.checkBoxOpen.TabIndex = 2   Me.checkBoxOpen.Text = "Open Picture after Export"   '   'groupBox1   '   Me.groupBox1.Controls.Add(Me.radioButtonColor)   Me.groupBox1.Controls.Add(Me.radioButtonGS)   Me.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.groupBox1.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.groupBox1.Location = New System.Drawing.Point(8, 248)   Me.groupBox1.Name = "groupBox1"   Me.groupBox1.Size = New System.Drawing.Size(216, 64)   Me.groupBox1.TabIndex = 12   Me.groupBox1.TabStop = False   Me.groupBox1.Text = "Color Format"   '   'radioButtonColor   '   Me.radioButtonColor.Checked = True   Me.radioButtonColor.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.radioButtonColor.Location = New System.Drawing.Point(8, 16)   Me.radioButtonColor.Name = "radioButtonColor"   Me.radioButtonColor.Size = New System.Drawing.Size(72, 24)   Me.radioButtonColor.TabIndex = 8   Me.radioButtonColor.TabStop = True   Me.radioButtonColor.Text = "Color"   '   'radioButtonGS   '   Me.radioButtonGS.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.radioButtonGS.Location = New System.Drawing.Point(8, 40)   Me.radioButtonGS.Name = "radioButtonGS"   Me.radioButtonGS.Size = New System.Drawing.Size(88, 21)   Me.radioButtonGS.TabIndex = 7   Me.radioButtonGS.Text = "Grayscale"   '   'groupBoxExportFormat   '   Me.groupBoxExportFormat.Controls.Add(Me.panel1)   Me.groupBoxExportFormat.Controls.Add(Me.radioButtonJPEG)   Me.groupBoxExportFormat.Controls.Add(Me.radioButtonBMP)   Me.groupBoxExportFormat.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.groupBoxExportFormat.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.groupBoxExportFormat.Location = New System.Drawing.Point(8, 104)   Me.groupBoxExportFormat.Name = "groupBoxExportFormat"   Me.groupBoxExportFormat.Size = New System.Drawing.Size(216, 133)   Me.groupBoxExportFormat.TabIndex = 11   Me.groupBoxExportFormat.TabStop = False   Me.groupBoxExportFormat.Text = "Export Format"   '   'panel1   '   Me.panel1.Controls.Add(Me.trackBar1)   Me.panel1.Controls.Add(Me.label7)   Me.panel1.Controls.Add(Me.label3)   Me.panel1.Controls.Add(Me.label4)   Me.panel1.Controls.Add(Me.labelQuality)   Me.panel1.Location = New System.Drawing.Point(8, 40)   Me.panel1.Name = "panel1"   Me.panel1.Size = New System.Drawing.Size(198, 64)   Me.panel1.TabIndex = 12   '   'trackBar1   '   Me.trackBar1.AutoSize = False   Me.trackBar1.Location = New System.Drawing.Point(8, 38)   Me.trackBar1.Maximum = 100   Me.trackBar1.Name = "trackBar1"   Me.trackBar1.Size = New System.Drawing.Size(185, 20)   Me.trackBar1.TabIndex = 9   Me.trackBar1.TickFrequency = 10   Me.trackBar1.Value = 85   '   'label7   '   Me.label7.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label7.Location = New System.Drawing.Point(14, 5)   Me.label7.Name = "label7"   Me.label7.Size = New System.Drawing.Size(120, 17)   Me.label7.TabIndex = 1   Me.label7.Text = "Quality/Compression:"   '   'label3   '   Me.label3.Font = New System.Drawing.Font("Tahoma", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label3.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))   Me.label3.Location = New System.Drawing.Point(102, 16)   Me.label3.Name = "label3"   Me.label3.Size = New System.Drawing.Size(87, 32)   Me.label3.TabIndex = 10   Me.label3.Text = "Highest Quality >>"   Me.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft   '   'label4   '   Me.label4.Font = New System.Drawing.Font("Tahoma", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label4.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))   Me.label4.Location = New System.Drawing.Point(11, 16)   Me.label4.Name = "label4"   Me.label4.Size = New System.Drawing.Size(90, 32)   Me.label4.TabIndex = 11   Me.label4.Text = "<< Smallest Size"   Me.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft   '   'labelQuality   '   Me.labelQuality.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.labelQuality.Location = New System.Drawing.Point(126, 5)   Me.labelQuality.Name = "labelQuality"   Me.labelQuality.Size = New System.Drawing.Size(51, 16)   Me.labelQuality.TabIndex = 3   '   'radioButtonJPEG   '   Me.radioButtonJPEG.Checked = True   Me.radioButtonJPEG.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.radioButtonJPEG.Location = New System.Drawing.Point(8, 24)   Me.radioButtonJPEG.Name = "radioButtonJPEG"   Me.radioButtonJPEG.Size = New System.Drawing.Size(120, 24)   Me.radioButtonJPEG.TabIndex = 8   Me.radioButtonJPEG.TabStop = True   Me.radioButtonJPEG.Text = "Compressed (JPEG)"   '   'radioButtonBMP   '   Me.radioButtonBMP.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.radioButtonBMP.Location = New System.Drawing.Point(8, 110)   Me.radioButtonBMP.Name = "radioButtonBMP"   Me.radioButtonBMP.Size = New System.Drawing.Size(197, 18)   Me.radioButtonBMP.TabIndex = 7   Me.radioButtonBMP.Text = "Uncompressed (Windows Bitmap)"   '   'groupBoxInfo   '   Me.groupBoxInfo.Controls.Add(Me.label22)   Me.groupBoxInfo.Controls.Add(Me.label5)   Me.groupBoxInfo.Controls.Add(Me.label2)   Me.groupBoxInfo.Controls.Add(Me.labelVRes)   Me.groupBoxInfo.Controls.Add(Me.labelHRes)   Me.groupBoxInfo.Controls.Add(Me.labelHeight)   Me.groupBoxInfo.Controls.Add(Me.labelWidth)   Me.groupBoxInfo.Controls.Add(Me.label1)   Me.groupBoxInfo.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.groupBoxInfo.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.groupBoxInfo.Location = New System.Drawing.Point(8, 0)   Me.groupBoxInfo.Name = "groupBoxInfo"   Me.groupBoxInfo.Size = New System.Drawing.Size(216, 96)   Me.groupBoxInfo.TabIndex = 9   Me.groupBoxInfo.TabStop = False   Me.groupBoxInfo.Text = "Image Information"   '   'label22   '   Me.label22.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label22.Location = New System.Drawing.Point(8, 72)   Me.label22.Name = "label22"   Me.label22.Size = New System.Drawing.Size(48, 16)   Me.label22.TabIndex = 6   Me.label22.Text = "V Res:"   '   'label5   '   Me.label5.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label5.Location = New System.Drawing.Point(8, 56)   Me.label5.Name = "label5"   Me.label5.Size = New System.Drawing.Size(40, 16)   Me.label5.TabIndex = 4   Me.label5.Text = "H Res:"   '   'label2   '   Me.label2.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label2.Location = New System.Drawing.Point(8, 40)   Me.label2.Name = "label2"   Me.label2.Size = New System.Drawing.Size(40, 16)   Me.label2.TabIndex = 1   Me.label2.Text = "Width:"   '   'labelVRes   '   Me.labelVRes.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.labelVRes.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.labelVRes.Location = New System.Drawing.Point(56, 72)   Me.labelVRes.Name = "labelVRes"   Me.labelVRes.Size = New System.Drawing.Size(64, 16)   Me.labelVRes.TabIndex = 7   '   'labelHRes   '   Me.labelHRes.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.labelHRes.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.labelHRes.Location = New System.Drawing.Point(56, 56)   Me.labelHRes.Name = "labelHRes"   Me.labelHRes.Size = New System.Drawing.Size(64, 16)   Me.labelHRes.TabIndex = 5   '   'labelHeight   '   Me.labelHeight.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.labelHeight.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.labelHeight.Location = New System.Drawing.Point(56, 24)   Me.labelHeight.Name = "labelHeight"   Me.labelHeight.Size = New System.Drawing.Size(64, 16)   Me.labelHeight.TabIndex = 2   '   'labelWidth   '   Me.labelWidth.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.labelWidth.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.labelWidth.Location = New System.Drawing.Point(56, 40)   Me.labelWidth.Name = "labelWidth"   Me.labelWidth.Size = New System.Drawing.Size(64, 16)   Me.labelWidth.TabIndex = 3   '   'label1   '   Me.label1.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.label1.Location = New System.Drawing.Point(8, 24)   Me.label1.Name = "label1"   Me.label1.Size = New System.Drawing.Size(48, 16)   Me.label1.TabIndex = 0   Me.label1.Text = "Height:"   '   'groupBoxPreview   '   Me.groupBoxPreview.Controls.Add(Me.pictureBox1)   Me.groupBoxPreview.Dock = System.Windows.Forms.DockStyle.Fill   Me.groupBoxPreview.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.groupBoxPreview.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.groupBoxPreview.Location = New System.Drawing.Point(0, 0)   Me.groupBoxPreview.Name = "groupBoxPreview"   Me.groupBoxPreview.Size = New System.Drawing.Size(656, 414)   Me.groupBoxPreview.TabIndex = 14   Me.groupBoxPreview.TabStop = False   Me.groupBoxPreview.Text = "Preview"   '   'pictureBox1   '   Me.pictureBox1.Location = New System.Drawing.Point(8, 24)   Me.pictureBox1.Name = "pictureBox1"   Me.pictureBox1.Size = New System.Drawing.Size(368, 344)   Me.pictureBox1.TabIndex = 0   Me.pictureBox1.TabStop = False   '   'panelBottom   '   Me.panelBottom.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle   Me.panelBottom.Controls.Add(Me.button1)   Me.panelBottom.Controls.Add(Me.buttonExport)   Me.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom   Me.panelBottom.Location = New System.Drawing.Point(0, 414)   Me.panelBottom.Name = "panelBottom"   Me.panelBottom.Size = New System.Drawing.Size(656, 32)   Me.panelBottom.TabIndex = 13   '   'button1   '   Me.button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)   Me.button1.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.button1.Location = New System.Drawing.Point(566, 5)   Me.button1.Name = "button1"   Me.button1.Size = New System.Drawing.Size(84, 21)   Me.button1.TabIndex = 1   Me.button1.Text = "Cancel"   '   'buttonExport   '   Me.buttonExport.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)   Me.buttonExport.FlatStyle = System.Windows.Forms.FlatStyle.System   Me.buttonExport.Location = New System.Drawing.Point(478, 5)   Me.buttonExport.Name = "buttonExport"   Me.buttonExport.Size = New System.Drawing.Size(84, 21)   Me.buttonExport.TabIndex = 0   Me.buttonExport.Text = "Export"   '   'frmExportPicture   '   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)   Me.ClientSize = New System.Drawing.Size(656, 446)   Me.Controls.Add(Me.panelExport)   Me.Controls.Add(Me.groupBoxPreview)   Me.Controls.Add(Me.panelBottom)   Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))   Me.Name = "frmExportPicture"   Me.Text = "Export Picture"   Me.panelExport.ResumeLayout(False)   Me.groupBox2.ResumeLayout(False)   Me.groupBox1.ResumeLayout(False)   Me.groupBoxExportFormat.ResumeLayout(False)   Me.panel1.ResumeLayout(False)   CType(Me.trackBar1, System.ComponentModel.ISupportInitialize).EndInit()   Me.groupBoxInfo.ResumeLayout(False)   Me.groupBoxPreview.ResumeLayout(False)   Me.panelBottom.ResumeLayout(False)   Me.ResumeLayout(False)   End Sub   #End Region   #Region "Locals"   Private _bmp As Bitmap   #End Region       Private Sub frmExportPicture_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load     Me.pictureBox1.Image = Me._bmp     Me.labelQuality.Text = Me.trackBar1.Value.ToString()     Me.labelHeight.Text = Me._bmp.Size.Height.ToString()   Me.labelWidth.Text = Me._bmp.Size.Height.ToString()   Me.labelHRes.Text = _bmp.HorizontalResolution.ToString()   Me.labelVRes.Text = _bmp.VerticalResolution.ToString()   End Sub   Private Sub SaveJPEG(ByVal theBitMap As Bitmap, ByVal filename As String)     Dim myImageCodecInfo As ImageCodecInfo   Dim myEncoder As Encoder   Dim myEncoderParameter As EncoderParameter   Dim myEncoderParameters As EncoderParameters     myImageCodecInfo = GetEncoderInfo("image/jpeg")   myEncoder = Encoder.Quality   myEncoderParameters = New EncoderParameters(1)     myEncoderParameter = New EncoderParameter(myEncoder, Me.trackBar1.Value)   myEncoderParameters.Param(0) = myEncoderParameter   theBitMap.Save(filename, myImageCodecInfo, myEncoderParameters)   End Sub   Private Sub SaveBMP(ByVal theBitMap As Bitmap, ByVal filename As String)     theBitMap.Save(filename)   End Sub       Private Sub buttonExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonExport.Click   Dim filename As String = String.Empty   Dim mask As String = String.Empty     Dim sfd As SaveFileDialog = New SaveFileDialog()     sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)   sfd.Title = "Save Picture"     If (Me.radioButtonBMP.Checked) Then     mask = "Bitmap File (*.bmp)|*.bmp"     filename = "Exported.bmp"   Else     mask = "JPEG File (*.JPEG)|*.JPEG"     filename = "Exported.JPEG"   End If     sfd.FileName = filename   sfd.Filter = mask   Dim dr As DialogResult = sfd.ShowDialog()   If (dr = DialogResult.OK) Then     Dim theBitMap As Bitmap       If (Me.radioButtonGS.Checked) Then       theBitMap = Me.ConvertAverageMatrix(_bmp)     Else       theBitMap = Me._bmp     End If       If (Me.radioButtonBMP.Checked) Then       SaveBMP(theBitMap, sfd.FileName)     Else       SaveJPEG(theBitMap, sfd.FileName)     End If   End If     sfd.Dispose()     If (Me.checkBoxOpen.Checked) Then     System.Diagnostics.Process.Start(filename)   End If   End Sub   Private Function ConvertAverageMatrix(ByVal BitmapIn As System.Drawing.Bitmap) As System.Drawing.Bitmap   Dim newB As Bitmap = CType(BitmapIn.Clone(), Bitmap)       Dim bounds As System.Drawing.Rectangle = New System.Drawing.Rectangle(0, 0, newB.Width, newB.Height)     Dim matrix As System.Drawing.Imaging.ColorMatrix = New System.Drawing.Imaging.ColorMatrix()     matrix(0, 0) = 1 / 3.0F   matrix(0, 1) = 1 / 3.0F   matrix(0, 2) = 1 / 3.0F   matrix(1, 0) = 1 / 3.0F   matrix(1, 1) = 1 / 3.0F   matrix(1, 2) = 1 / 3.0F   matrix(2, 0) = 1 / 3.0F   matrix(2, 1) = 1 / 3.0F   matrix(2, 2) = 1 / 3.0F     Dim attributes As System.Drawing.Imaging.ImageAttributes = New System.Drawing.Imaging.ImageAttributes()   attributes.SetColorMatrix(matrix)     Dim graphics As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(newB)   Graphics.DrawImage(newB, bounds, 0, 0, newB.Width, newB.Height, System.Drawing.GraphicsUnit.Pixel, attributes)   Graphics.Dispose()     Return newB   End Function   Private Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo     Dim j As Integer = 0   Dim encoders As ImageCodecInfo()     encoders = ImageCodecInfo.GetImageEncoders()   For j = 0 To encoders.Length     If (encoders(j).MimeType = mimeType) Then       Return encoders(j)     End If   Next j     Return Nothing   End Function   Private Sub trackBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles trackBar1.ValueChanged     Me.labelQuality.Text = trackBar1.Value.ToString()   End Sub   Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click   Me.Close()   End Sub End Class