Versión Copiada del tfs
This commit is contained in:
32
Imagen.vb
Normal file
32
Imagen.vb
Normal file
@@ -0,0 +1,32 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Drawing.Drawing2D
|
||||
Imports System.Drawing.Imaging
|
||||
|
||||
|
||||
|
||||
Public Class Imagen
|
||||
Public Shared Function ResizeImage(ByVal image As Image, _
|
||||
ByVal size As Size, Optional ByVal preserveAspectRatio As Boolean = True) As Image
|
||||
Dim newWidth As Integer
|
||||
Dim newHeight As Integer
|
||||
If preserveAspectRatio Then
|
||||
Dim originalWidth As Integer = image.Width
|
||||
Dim originalHeight As Integer = image.Height
|
||||
Dim percentWidth As Single = CSng(size.Width) / CSng(originalWidth)
|
||||
Dim percentHeight As Single = CSng(size.Height) / CSng(originalHeight)
|
||||
Dim percent As Single = If(percentHeight < percentWidth,
|
||||
percentHeight, percentWidth)
|
||||
newWidth = CInt(originalWidth * percent)
|
||||
newHeight = CInt(originalHeight * percent)
|
||||
Else
|
||||
newWidth = size.Width
|
||||
newHeight = size.Height
|
||||
End If
|
||||
Dim newImage As Image = New Bitmap(newWidth, newHeight)
|
||||
Using graphicsHandle As Graphics = Graphics.FromImage(newImage)
|
||||
graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic
|
||||
graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight)
|
||||
End Using
|
||||
Return newImage
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user