BmpTransforms.vb
  1. ''
  2. '' This code is part of Document Solutions for Imaging demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Numerics
  8. Imports GrapeCity.Documents.Drawing
  9. Imports GrapeCity.Documents.Text
  10. Imports GrapeCity.Documents.Imaging
  11.  
  12. '' This sample demonstrates how to use bitmap transformations
  13. '' such as resizing, flipping and rotating.
  14. Public Class Transforms
  15. Function GenerateImage(
  16. ByVal pixelSize As Size,
  17. ByVal dpi As Single,
  18. ByVal opaque As Boolean,
  19. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  20.  
  21. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
  22. bmp.Clear(Color.Transparent)
  23.  
  24. Dim side = pixelSize.Width / 2
  25. Dim side2 = side / 2
  26. Dim bmpLarge, bmpFlip, bmpSmall1, bmpSmall2, bmpSmall3, bmpSmall4
  27. Using bmpSrc = New GcBitmap(Path.Combine("Resources", "Stock", "goldfish.jpg"))
  28. bmpSrc.Opaque = opaque
  29. bmpLarge = bmpSrc.Resize(side, side)
  30. bmpFlip = bmpLarge.FlipRotate(FlipRotateAction.FlipHorizontal)
  31. bmpSmall1 = bmpSrc.Resize(side2, side2)
  32. bmpSmall2 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate270)
  33. bmpSmall3 = bmpSmall1.FlipRotate(FlipRotateAction.FlipVertical)
  34. bmpSmall4 = bmpSmall1.FlipRotate(FlipRotateAction.Rotate90)
  35. End Using
  36.  
  37. bmp.BitBlt(bmpLarge, 0, 0)
  38. bmp.BitBlt(bmpFlip, pixelSize.Width - bmpFlip.Width, 0)
  39. bmp.BitBlt(bmpSmall1, 0, side + side2 / 2)
  40. bmp.BitBlt(bmpSmall2, side2, side + side2 / 2)
  41. bmp.BitBlt(bmpSmall3, side2 * 2, side + side2 / 2)
  42. bmp.BitBlt(bmpSmall4, side2 * 3, side + side2 / 2)
  43.  
  44. '' Dispose bitmaps except the resulting one
  45. bmpLarge.Dispose()
  46. bmpFlip.Dispose()
  47. bmpSmall1.Dispose()
  48. bmpSmall2.Dispose()
  49. bmpSmall3.Dispose()
  50. bmpSmall4.Dispose()
  51.  
  52. Return bmp
  53. End Function
  54. End Class
  55.  
  56.