''
'' 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 draw a window with a solid frame
'' and four semi-transparent colored window panes,
'' floating above a solid brick wall with some text written on it,
'' and casting a semi-transparent colored shadow on the wall.
Public Class TransparentShadow
Private _font As GCTEXT.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "KaushanScript-Regular.ttf"))
Public Function GenerateImage(
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
Optional ByVal sampleParams As String() = Nothing) As GcBitmap
'' A temporary bitmap to hold the shadow:
Using shadow As New GcBitmap(pixelSize.Width, pixelSize.Height, False)
'' Draw the window on the shadow bitmap; the offsetX/offsetY (64/82)
'' account for the shadow's offset relative to the floating window:
Using g = shadow.CreateGraphics(Color.Transparent)
DrawWindow(g, pixelSize, 64, 82)
End Using
'' Create a shadow without blur for colored panes:
Using gs = shadow.ToGrayscaleBitmap(ColorChannel.Alpha)
Using shadowTemp = gs.ToShadowBitmap(Color.DarkSlateGray)
shadow.AlphaBlend(shadowTemp, 0, 0)
End Using
End Using
'' Apply blur and transparency:
shadow.ApplyEffect(GaussianBlurEffect.Get(29))
shadow.ApplyEffect(OpacityEffect.Get(0.85F))
'' Prepare the brick wall:
Dim wall As New GcBitmap(pixelSize.Width, pixelSize.Height, True)
Using g = wall.CreateGraphics(Color.DarkSalmon)
DrawWall(g, pixelSize)
End Using
'' Blend the shadow with the wall:
wall.AlphaBlend(shadow, 0, 0)
'' Draw the window in front:
Using g = wall.CreateGraphics()
DrawWindow(g, pixelSize, 0, 0)
End Using
Return wall
End Using
End Function
'' Draw a window with four colored semi-transparent panes:
Private Sub DrawWindow(ByVal g As GcGraphics, ByVal pixelSize As Size, ByVal offsetX As Single, ByVal offsetY As Single)
Dim w = pixelSize.Width * 0.4F
Dim h = pixelSize.Height * 0.5F
Dim x = pixelSize.Width / 2 - w / 2
Dim y = pixelSize.Height / 2 - h / 2
g.Transform = Matrix3x2.CreateTranslation(offsetX, offsetY)
Dim wnd = New RectangleF(x, y, w, h)
Dim winHalf = New SizeF(wnd.Width / 2, wnd.Height / 2)
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)
Dim outline = Color.DarkSlateGray
g.DrawRectangle(wnd, New GCDRAW.Pen(outline, 34))
g.DrawLine(wnd.Left, wnd.Top + wnd.Height / 2, wnd.Right, wnd.Top + wnd.Height / 2, outline, 24)
g.DrawLine(wnd.Left + wnd.Width / 2, wnd.Top, wnd.Left + wnd.Width / 2, wnd.Bottom, outline, 24)
Dim frame = Color.LightGoldenrodYellow
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
'' Draw a brick wall with white text:
Private Sub DrawWall(ByVal g As GcGraphics, ByVal pixelSize As Size)
Dim brick = New Size(112, 44)
Dim pen = New GCDRAW.Pen(Color.DimGray, 2)
Dim off = brick.Width / 2
For y = -brick.Height / 3 To pixelSize.Height - 1 Step brick.Height
For x = off + brick.Width / 3 To pixelSize.Width - 1 Step brick.Width
g.DrawLine(x, y, x, y + brick.Height, pen)
Next
off = If(off = 0, brick.Width / 2, 0)
g.DrawLine(0, y, pixelSize.Width, y, pen)
Next
'' Graffiti-like white text:
Dim tl = g.CreateTextLayout()
tl.MaxWidth = pixelSize.Width
tl.MaxHeight = pixelSize.Height
tl.ParagraphAlignment = ParagraphAlignment.Center
tl.TextAlignment = TextAlignment.Center
tl.DefaultFormat.Font = _font
tl.DefaultFormat.FontSize = 270
tl.DefaultFormat.ForeColor = Color.White
tl.ParagraphSpacing = -120
tl.Append("The" & vbLf & "Wall")
g.BlendMode = BlendMode.Overlay
g.DrawTextLayout(tl, Point.Empty)
g.BlendMode = BlendMode.Normal
End Sub
End Class