In. NET, you can easily compress the quality of your picture files

Source: Internet
Author: User
Tags integer net save file tostring
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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.