AllBlendingModes.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.Collections.Generic
  8. Imports System.Linq
  9. Imports System.Numerics
  10. Imports GrapeCity.Documents.Drawing
  11. Imports GrapeCity.Documents.Text
  12. Imports GrapeCity.Documents.Imaging
  13. Imports GCTEXT = GrapeCity.Documents.Text
  14. Imports GCDRAW = GrapeCity.Documents.Drawing
  15.  
  16. '' This sample demonstrates composing two images using the available blending modes.
  17. '' The sample uses the same approach as the BlendingModes sample,
  18. '' but instead of showing a few of the available modes that produce
  19. '' a nice looking result, demonstrates all of them in smaller scale.
  20. '' The base and the blended images used as the same as in the BlendingModes sample.
  21. Public Class AllBlendingModes
  22. Function GenerateImage(
  23. ByVal pixelSize As Size,
  24. ByVal dpi As Single,
  25. ByVal opaque As Boolean,
  26. Optional ByVal sampleParams As String() = Nothing) As GcBitmap
  27.  
  28. Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
  29. Using origBmp = New GcBitmap(), spectrumBmp = New GcBitmap()
  30. '' Load a sample photo:
  31. Dim imagePath = Path.Combine("Resources", "ImagesBis", "orchid.jpg")
  32. Using stm = New FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)
  33. origBmp.Load(stm)
  34. End Using
  35.  
  36. '' Blending source:
  37. Dim spectrumPath = Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png")
  38. Using stm = New FileStream(spectrumPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)
  39. spectrumBmp.Load(stm)
  40.  
  41. spectrumBmp.Opaque = opaque
  42. origBmp.Opaque = opaque
  43.  
  44. '' Resize the original photo so we can place 4 samples of it
  45. '' on the resulting bitmap:
  46. Dim w = pixelSize.Width / 4
  47. Dim h = pixelSize.Height / 4
  48. Using g = bmp.CreateGraphics()
  49. '' Prepare for captions:
  50. Dim tl = g.CreateTextLayout()
  51. tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "cour.ttf"))
  52. tl.DefaultFormat.FontSize = 12
  53. tl.ParagraphAlignment = ParagraphAlignment.Center
  54. tl.TextAlignment = TextAlignment.Center
  55. tl.MaxWidth = w
  56. tl.MaxHeight = h
  57. tl.MarginTop = h - g.MeasureString("QWERTY", tl.DefaultFormat).Height * 1.4F
  58. '' Render all 16 blending modes in a 4x4 grid
  59. Using sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic),
  60. sizedSpectrumBmp = spectrumBmp.Resize(w, h)
  61. For row = 0 To 3
  62. For col = 0 To 3
  63. '' Sample:
  64. Dim blendMode = CType(row * 4 + col, BlendMode)
  65. Dim x = w * col, y = h * row
  66. bmp.BitBlt(sizedBmp, x, y)
  67. bmp.CompositeAndBlend(sizedSpectrumBmp, x, y, CompositeMode.SourceOver, blendMode)
  68. '' Caption:
  69. tl.Clear()
  70. tl.Append(blendMode.ToString())
  71. tl.PerformLayout(True)
  72. Dim rc = tl.ContentRectangle
  73. rc.Offset(x, y)
  74. rc.Inflate(4, 2)
  75. g.FillRectangle(rc, Color.White)
  76. g.DrawTextLayout(tl, New PointF(x, y))
  77. Next
  78. Next
  79. End Using
  80. End Using
  81. End Using
  82. End Using
  83. Return bmp
  84. End Function
  85. End Class
  86.