Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Sub Resize(ByVal maxWidth As Integer, ByVal maxHeight As Integer, ByVal bSaveAspect As Boolean)
- Dim thumbImg As System.Drawing.Image
- Dim objCB As System.Drawing.Image.GetThumbnailImageAbort = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCB)
- Dim newWidth As Integer = AWImage.Size.Width
- Dim newHeight As Integer = AWImage.Size.Height
- If bSaveAspect = True Then
- If AWImage.Size.Height > maxHeight OrElse AWImage.Size.Width > maxWidth Then
- If CDbl(AWImage.Size.Height) / CDbl(maxHeight) > CDbl(AWImage.Size.Width) / CDbl(maxWidth) Then
- newHeight = maxHeight
- Dim k As Double = CDbl(maxHeight) / CDbl(AWImage.Size.Height)
- newWidth = CInt(Math.Round(k * AWImage.Size.Width))
- Else
- Dim k As Double = CDbl(maxWidth) / CDbl(AWImage.Size.Width)
- newHeight = CInt(Math.Round(k * AWImage.Size.Height))
- newWidth = maxWidth
- End If
- End If
- thumbImg = AWImage
- If newWidth > 0 AndAlso newHeight > 0 Then
- AWImage.RotateFlip(RotateFlipType.Rotate180FlipNone)
- AWImage.RotateFlip(RotateFlipType.Rotate180FlipNone)
- thumbImg = AWImage.GetThumbnailImage(newWidth, newHeight, objCB, IntPtr.Zero)
- AWImage.Dispose()
- AWImage = thumbImg
- End If
- Else
- thumbImg = AWImage.GetThumbnailImage(maxWidth, maxHeight, objCB, IntPtr.Zero)
- AWImage.Dispose()
- AWImage = thumbImg
- End If
- End Sub
- Function ThumbnailCB() As Boolean
- Return True
- End Function
Add Comment
Please, Sign In to add comment