''
'' 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 System.Collections.Generic
Imports System.Linq
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' This example shows how to create a semi-transparent blurred shadow
'' of a text and graphics image, offset by a specified amount.
'' To achieve this the code employs the ApplyGaussianBlur and ToShadowBitmap
'' methods of the GrayscaleBitmap class.
Public Class Shadow
Private _font As GCTEXT.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf"))
Public Function GenerateImage(
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
Optional ByVal sampleParams As String() = Nothing) As GcBitmap
'' Create a transparent bitmap and draw the shadow image on it (offset left/down by 30/50):
Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, False)
Using g = bmp.CreateGraphics(Color.Transparent)
Draw(g, 30, 50)
End Using
'' Extract the alpha channel from GcBitmap to a GrayscaleBitmap:
Using gs = bmp.ToGrayscaleBitmap(ColorChannel.Alpha)
'' Blur the GrayscaleBitmap to create a believable looking shadow:
gs.ApplyGaussianBlur(9)
'' Convert the transparency mask from GrayscaleBitmap to GcBitmap,
'' filling the opaque pixels with the shadow color (CadetBlue),
'' also making the resulting 'shadow' slightly transparent (0.6f):
gs.ToShadowBitmap(bmp, Color.CadetBlue, 0.6F)
End Using
'' Replace the transparent background with an opaque background color:
bmp.ConvertToOpaque(Color.LightGoldenrodYellow)
'' Finally draw the original image without offset on top:
Using g = bmp.CreateGraphics()
Draw(g, 0, 0)
End Using
'' Done
Return bmp
End Function
Private Sub Draw(ByVal g As GcGraphics, ByVal offsetX As Single, ByVal offsetY As Single)
Dim baseT = Matrix3x2.CreateTranslation(offsetX, offsetY)
g.Transform = baseT
g.DrawEllipse(New RectangleF(100, 100, 300, 200), New GCDRAW.Pen(Color.Orange, 20))
g.DrawLine(New PointF(50, 400), New PointF(500, 50), New GCDRAW.Pen(Color.RoyalBlue, 20) With {
.LineCap = PenLineCap.Round
})
g.DrawString("Howl's Moving Castle",
New TextFormat With {
.Font = _font,
.FontSize = 40,
.ForeColor = Color.MistyRose,
.StrokePen = New GCDRAW.Pen(Color.DarkRed, 1)
},
New PointF(200, 150))
g.Transform =
Matrix3x2.CreateRotation(CSng(Math.PI / 6)) *
(Matrix3x2.CreateTranslation(50, 250) * baseT)
g.DrawString("The quick brown fox jumps over the lazy dog.",
New TextFormat With {
.Font = _font,
.FontSize = 18,
.ForeColor = Color.CornflowerBlue
},
New PointF(0, 0))
g.DrawRectangle(New RectangleF(-15, -10, 470, 50), New GCDRAW.Pen(Color.Salmon, 1))
g.Transform = baseT
'' Draw a window with four colored semi-transparent panes:
Dim wnd = New RectangleF(520, 420, 400, 500)
Dim winHalf = New SizeF(wnd.Width / 2, wnd.Height / 2)
Dim frame = Color.Brown
Dim glassTL = Color.FromArgb(&H70FF4600)
Dim glassTR = Color.FromArgb(&H70A5FF00)
Dim glassBL = Color.FromArgb(&H70007BFF)
Dim glassBR = Color.FromArgb(&H70FFCD00)
g.FillRectangle(New RectangleF(wnd.Location, winHalf), glassTL)
g.FillRectangle(New RectangleF(New PointF(wnd.X + wnd.Width / 2, wnd.Y), winHalf), glassTR)
g.FillRectangle(New RectangleF(New PointF(wnd.X, wnd.Y + wnd.Height / 2), winHalf), glassBL)
g.FillRectangle(New RectangleF(New PointF(wnd.X + wnd.Width / 2, wnd.Y + wnd.Height / 2), winHalf), glassBR)
g.DrawRectangle(wnd, New GCDRAW.Pen(frame, 30))
g.DrawLine(wnd.Left, wnd.Top + wnd.Height / 2, wnd.Right, wnd.Top + wnd.Height / 2, frame, 20)
g.DrawLine(wnd.Left + wnd.Width / 2, wnd.Top, wnd.Left + wnd.Width / 2, wnd.Bottom, frame, 20)
g.Transform = Matrix3x2.Identity
End Sub
End Class