ImageTransparency.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing

'' 该示例演示了 GcDocs.Pdf 渲染的能力
'' 使用指定透明度(不透明度)的图像。
Public Class ImageTransparency
    Function CreatePDF(ByVal stream As Stream) As Integer
        Dim doc = New GcPdfDocument()
        Dim page = doc.NewPage()
        Dim g = page.Graphics

        Dim rc = Util.AddNote(
            "GcPdfGraphics.DrawImage() 方法允许渲染具有指定不透明度的图像。" +
            "",
            page)

        Dim tl = g.CreateTextLayout()
        tl.DefaultFormat.Font = StandardFonts.Times
        tl.DefaultFormat.FontSize = 12
        tl.MaxWidth = page.Size.Width
        tl.MaxHeight = page.Size.Height
        tl.MarginAll = 36
        tl.MarginTop += rc.Bottom
        tl.Append(Util.LoremIpsum(2))
        tl.PerformLayout(True)
        g.DrawTextLayout(tl, PointF.Empty)

        Using img As GCDRAW.Image = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "puffins.jpg"))
            Dim imageRc = New RectangleF(tl.MarginLeft, tl.MarginTop, 144, 144)
            '' 不透明度0.2:
            g.DrawImage(img, imageRc, Nothing, ImageAlign.ScaleImage, 0.2F)
            imageRc.Offset(imageRc.Width + 36, 0)
            '' 不透明度0.5:
            g.DrawImage(img, imageRc, Nothing, ImageAlign.ScaleImage, 0.5F)
            imageRc.Offset(imageRc.Width + 36, 0)
            '' 不透明度 1(默认):
            g.DrawImage(img, imageRc, Nothing, ImageAlign.ScaleImage)

            '' 注意:我们必须在处理文档中使用的图像之前保存文档:
            doc.Save(stream)
        End Using
        Return doc.Pages.Count
    End Function
End Class