''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' This example uses the GaussianBlurEffect to draw semi-transparent colored circles ('filters'),
'' blurring the portion of the image behind them.
Public Class GaussianBlur2
Public Function GenerateImage(
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
Optional ByVal sampleParams As String() = Nothing) As GcBitmap
Dim colors = New Color() {
Color.Fuchsia,
Color.Orange,
Color.Black,
Color.Blue,
Color.Red,
Color.Yellow,
Color.White,
Color.Green,
Color.CornflowerBlue
}
colors.Shuffle()
Dim imagePath = Path.Combine("Resources", "ImagesBis", "bahamas.jpg")
Dim bmp = New GcBitmap(imagePath)
Dim xx = bmp.PixelWidth \ 3
Dim yy = bmp.PixelHeight \ 3
Dim maxr = Math.Min(xx \ 2, yy \ 2)
Dim rnd = Util.NewRandom()
Using bmpBk = bmp.Clone()
'' Apply blur to a copy of the original bitmap:
bmpBk.ApplyEffect(GaussianBlurEffect.Get(24, GaussianBlurBorderMode.RepeatEdge))
Using g = bmp.CreateGraphics()
Dim renderer = g.Renderer
For i As Integer = 0 To 8
Dim r = rnd.Next(maxr \ 3, maxr)
Dim center = New PointF(rnd.Next(r, xx - r) + (i Mod 3) * xx + 1, rnd.Next(r, yy - r) + (i \ 3) * yy + 1)
Dim rect = New RectangleF(center.X - r, center.Y - r, r + r, r + r)
Dim color = colors(i)
'' Use the blurred background to fill circles:
renderer.BackgroundBitmap = bmpBk
g.FillEllipse(rect, Color.FromArgb(96, color))
'' Draw borders normally to hide the artifacts:
renderer.BackgroundBitmap = Nothing
g.DrawEllipse(rect, New GCDRAW.Pen(color, 2))
Next
End Using
End Using
Return bmp
End Function
End Class