Sub RotateAndZoomImage(loadfile As String, savefile As String, angle As Integer) Dim Image As New System.Drawing.Bitmap(loadfile) ' Opret en tom bitmap med den ønskede størrelse Dim targetWidth As Integer = Image.Width Dim scale2 As Double Dim targetHeight As Integer = Image.Height Dim rotatedBmp As New Bitmap(targetWidth, targetHeight) rotatedBmp.SetResolution(Image.HorizontalResolution, Image.VerticalResolution) ' Opret en grafisk kontekst Using g As Graphics = Graphics.FromImage(rotatedBmp) ' Indstil grafiske parametre g.InterpolationMode = InterpolationMode.HighQualityBicubic g.PixelOffsetMode = PixelOffsetMode.HighQuality g.SmoothingMode = SmoothingMode.AntiAlias ' Flyt origin til midten af den nye bitmap g.TranslateTransform(targetWidth / scale2, targetHeight / scale2) ' Roter grafikken g.RotateTransform(angle) ' Beregn skalering for at tilpasse billedet til den nye størrelse Dim scale As Single = Math.Max(targetWidth / Image.Width, targetHeight / Image.Height) g.ScaleTransform(scale, scale) ' Tegn det roterede og skalerede billede g.DrawImage(Image, -CSng(Image.Width), -CSng(Image.Height), CSng(Image.Width * scale2), CSng(Image.Height * scale2)) End Using rotatedBmp.Save(savefile, ImageFormat.Jpeg) rotatedBmp.Dispose() Image.Dispose() End Sub
scale2
Double
Single
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)