Public Class Form1 ''' <summary> ''' Scales a bitmap to the specified width and height using high quality bicubic scaling. ''' </summary> ''' <param name="b">The original bitmap.</param> ''' <param name="width">The new width of the bitmap.</param> ''' <param name="height">The new height of the bitmap.</param> ''' <returns>The scaled bitmap.</returns> ''' <remarks></remarks> Public Shared Function Scales(ByVal b As Bitmap, ByVal width As Integer, ByVal height As Integer, ByVal resol As Integer) As Bitmap If b Is Nothing Then Throw New ArgumentNullException If width <= 0 Or height <= 0 Then Throw New ArgumentException("The width and height must be greater than zero.") Dim sb As New Bitmap(width, height, b.PixelFormat) Dim gr As Graphics = Graphics.FromImage(sb) gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic gr.DrawImage(b, New Rectangle(0, 0, width, height)) sb.SetResolution(CInt(resol), CInt(resol)) 'resolution gr.Dispose() Return sb End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim b As New Bitmap("chemin fichier.jpg") b = Scales(b, 100, 50, 72) b.Save("chemin fichier_copie.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question