Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. Public Sub Resize(ByVal maxWidth As Integer, ByVal maxHeight As Integer, ByVal bSaveAspect As Boolean)
  2. Dim thumbImg As System.Drawing.Image
  3. Dim objCB As System.Drawing.Image.GetThumbnailImageAbort = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCB)
  4. Dim newWidth As Integer = AWImage.Size.Width
  5. Dim newHeight As Integer = AWImage.Size.Height
  6.  
  7. If bSaveAspect = True Then
  8. If AWImage.Size.Height > maxHeight OrElse AWImage.Size.Width > maxWidth Then
  9. If CDbl(AWImage.Size.Height) / CDbl(maxHeight) > CDbl(AWImage.Size.Width) / CDbl(maxWidth) Then
  10. newHeight = maxHeight
  11. Dim k As Double = CDbl(maxHeight) / CDbl(AWImage.Size.Height)
  12. newWidth = CInt(Math.Round(k * AWImage.Size.Width))
  13. Else
  14. Dim k As Double = CDbl(maxWidth) / CDbl(AWImage.Size.Width)
  15. newHeight = CInt(Math.Round(k * AWImage.Size.Height))
  16. newWidth = maxWidth
  17. End If
  18. End If
  19. thumbImg = AWImage
  20. If newWidth > 0 AndAlso newHeight > 0 Then
  21. AWImage.RotateFlip(RotateFlipType.Rotate180FlipNone)
  22. AWImage.RotateFlip(RotateFlipType.Rotate180FlipNone)
  23. thumbImg = AWImage.GetThumbnailImage(newWidth, newHeight, objCB, IntPtr.Zero)
  24. AWImage.Dispose()
  25. AWImage = thumbImg
  26. End If
  27. Else
  28. thumbImg = AWImage.GetThumbnailImage(maxWidth, maxHeight, objCB, IntPtr.Zero)
  29. AWImage.Dispose()
  30. AWImage = thumbImg
  31. End If
  32. End Sub
  33. Function ThumbnailCB() As Boolean
  34. Return True
  35. End Function
Add Comment
Please, Sign In to add comment