Пишем функцию:
Public Function ScaleByPercent(ByVal imgPhoto As Image, ByVal Width As Integer, ByVal Height As Integer) As Image
Dim sourceWidth As Integer = imgPhoto.Width
Dim sourceHeight As Integer = imgPhoto.Height
Dim sourceX As Integer = 0
Dim sourceY As Integer = 0
Dim destX As Integer = 0
Dim destY As Integer = 0
Dim nPercent As Single = 0
Dim nPercentW As Single = 0
Dim nPercentH As Single = 0
nPercentW = (CSng(Width) / CSng(sourceWidth))
nPercentH = (CSng(Height) / CSng(sourceHeight))
If nPercentH < nPercentW Then
nPercent = nPercentH
Else
nPercent = nPercentW
End If
Dim destWidth As Integer = CInt((sourceWidth * nPercent))
Dim destHeight As Integer = CInt((sourceHeight * nPercent))
Dim bmPhoto As New Bitmap(destWidth, destHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution)
Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel)
grPhoto.Dispose()
Return (bmPhoto)
End FunctionИспользование:
Dim kartinka As Bitmap
kartinka = ScaleByPercent(Image.FromFile("Путь к файлу исходной картинки"), 100, 200)
kartinka.Save("Путь к файлу новой картинки")Где 100 максимальная ширина картинки, 200 максимальная высота картинки