GcLogoHtml.vb
''
'' This code is part of GrapeCity Documents for Imaging samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Linq
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GrapeCity.Documents.Html

'' This sample uses the same code as in the HelloWorld sample
'' to create an image with the "Hello, World!" text, but in addition
'' adds the GrapeCity logo copied from the GrapeCity home page
'' using GcHtml.
''
'' Please see notes in comments at the top of HelloWorldHtml
'' sample code for details on adding GcHtml to your projects.
Public Class GcLogoHtml
    Function GenerateImage(
            Optional pixelWidth As Integer = 1024,
            Optional pixelHeight As Integer = 1024,
            Optional opaque As Boolean = True,
            Optional dpiX As Single = 96,
            Optional dpiY As Single = 96) As GcBitmap

        '' The GrapeCity home page:
        Dim uri = New Uri("https://www.grapecity.com/")
        '' The coordinates of the GrapeCity logo on the home page:
        Dim logoRc = New RectangleF(5, 0, 180, 120)

        '' Create the "Hello, World!" image like in the HelloWorld sample:
        Dim blue = Color.FromArgb(&HFF2E4884)
        Dim bmp = New GcBitmap(pixelWidth, pixelHeight, True, dpiX, dpiY)
        Using g = bmp.CreateGraphics(blue)
            Dim rc = New RectangleF(0, 0, pixelWidth, pixelHeight)
            Dim b = New RadialGradientBrush(Color.White, blue, New PointF(0.5F, 0.5F), True)
            g.FillRectangle(rc, b)
            Dim tf = New TextFormat With
                {
                    .Font = Font.FromFile(Path.Combine("Resources", "Fonts", "timesbd.ttf")),
                    .FontSize = 64,
                    .ForeColor = Color.OrangeRed
                }
            g.DrawString("Hello, World!", tf, rc, TextAlignment.Center, ParagraphAlignment.Center, False)

            '' Copy And paste the logo from the GrapeCity home page onto the image, scaled x2:
            Dim fmt = New HtmlToImageFormat(False) With
                {
                    .Clip = logoRc,
                    .Scale = 2
                }
            Dim s As SizeF
            g.DrawHtml(uri, pixelWidth - logoRc.Width * fmt.Scale, 0, fmt, s)
        End Using
        Return bmp
    End Function
End Class