Her er et eks. på ændring af størrelse og compression:
Kode..........................................: ' Get the source bitmap. Dim bm_source As New Bitmap(Me.path & picture)
' Make a bitmap for the result. Dim bm_dest As New Bitmap( _ CInt(Me.ImageWidth), _ CInt(Me.ImageHeight))
' Make a Graphics object for the result Bitmap. Dim gr_dest As Graphics = Graphics.FromImage(bm_dest)
' Copy the source image into the destination bitmap. gr_dest.DrawImage(bm_source, 0, 0, _ bm_dest.Width + 1, _ bm_dest.Height + 1)
' Display the result. bm_dest.Save(Me.path & tmpPicture)
Dim tmp As Image = Image.FromFile(Me.path & tmpPicture) Me.SaveJPGWithCompressionSetting(tmp, Me.path & "r" & picture, Me.JPEGCompression)
HJÆLPEMETODER.............................................: Private Sub SaveJPGWithCompressionSetting(ByVal image As Image, ByVal szFileName As String, ByVal lCompression As Long) Dim eps As EncoderParameters = New EncoderParameters(1) eps.Param(0) = New EncoderParameter(Encoder.Quality, _ lCompression) Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg") image.Save(szFileName, ici, eps) End Sub
Private Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo Dim j As Integer 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
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.