Compression
'***********************************************************
' Instant Preview to save picture quality
' Wgscd (c) 153964481,email:wgscd@126.com QQ
Dim Pulicimagecodecinfo as ImageCodecInfo ' Define global variables improve efficiency
Dim Myimagecodecinfo as System.Drawing.Imaging.ImageCodecInfo
Dim Myencoder as System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
Dim Myencoderparameter as System.Drawing.Imaging.EncoderParameter
Dim Myencoderparameters as System.Drawing.Imaging.EncoderParameters
Private Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Mybase.lo Ad
me.text = Save file
Me.Label2.Text = "Instant preview save picture quality wgscd (c) 02005 using Imagecodecinfo,system.drawing.imaging.encoder "
Me.HScrollBar1.Cursor = Cursors.hand
pulicimagecodecinfo = Getencoderinfo ("Image/jpeg") ' Get ImageCodecInfo
Me.PictureBox2.Image.Save ("c:\wgscd.jpg")
Me.PictureBox3.Image = Image.FromFile ("c:\wgscd.jpg")
Dim fi as New FileInfo ("C:\wgscd.jpg")
fi = New FileInfo ("C:\wgscd.jpg")
Label1.Text = hscrollbar1.value & "Size:" & (FI. length/1024). ToString ("0.00") & "KB"
Me.PictureBox3.Refresh () ' must be released
Me.PictureBox3.Image.Dispose ()
Me.PictureBox3.Image = Me.PictureBox2.Image
End Sub
Private Sub Hscrollbar1_scroll (ByVal sender as System.Object, ByVal e as System.Windows.Forms.ScrollEventArgs) Handles HS Crollbar1.scroll
' Dim Mymemorystream as IO. MemoryStream = New IO. MemoryStream
Myimagecodecinfo = Pulicimagecodecinfo ' Set with global saved ImageCodecInfo
Myencoderparameters = New System.Drawing.Imaging.EncoderParameters (1)
' Myencoderparameter = New System.Drawing.Imaging.EncoderParameter (myencoder, ENCODERVALUE.TRANSFORMROTATE90)
Myencoderparameter = New System.Drawing.Imaging.EncoderParameter (myencoder, CLng (Me.HScrollBar1.Value))
Myencoderparameters.param (0) = Myencoderparameter
' Me.PictureBox2.Save (Mymemorystream, Myimagecodecinfo, myencoderparameters) ' writes like a memory stream
Try
Me.PictureBox2.Image.Save ("C:\wgscd.jpg", Myimagecodecinfo, Myencoderparameters)
Me.PictureBox3.Image = Image.FromFile ("c:\wgscd.jpg")
Dim fi as New FileInfo ("C:\wgscd.jpg")
fi = New FileInfo ("C:\wgscd.jpg")
Label1.Text = "Save quality:" & hscrollbar1.value & "% Size:" & (FI. length/1024). ToString ("0.00") & "KB"
Me.PictureBox3.Refresh () ' must be released
Me.PictureBox3.Image.Dispose ()
' Myencoderparameters.dispose ()
' Mymemorystream.flush ()
Catch ex as Exception
' If it is necessary to handle errors, add code
' MsgBox (ex. ToString)
End Try
End Sub '
Private Sub button2_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button2.click
Me.close ()
End Sub
' Can get the imageencoders of the system
Sub Getimageencoders ()
Dim I as Integer
Dim encoders as System.Drawing.Imaging.ImageCodecInfo () = Imaging.ImageCodecInfo.GetImageEncoders
For i = 0 to (encoders. LENGTH-1)
MsgBox (Encoders (i). MimeType)
Next I
End Sub
Private Function Getencoderinfo (ByVal Mymimetype as String) as ImageCodecInfo
Dim I as Integer
Dim encoders as System.Drawing.Imaging.ImageCodecInfo () = Imaging.ImageCodecInfo.GetImageEncoders ()
For i = 0 to (encoders. LENGTH-1)
If (Encoders (i). MimeType = Mymimetype) Then
' MsgBox (encoders (i). MimeType)
return Encoders (i)
End If
Next I
End Function