AllBlendingModes.vb
'' 
'' このコードは、DioDocs for Imaging のサンプルの一部として提供されています。
'' © MESCIUS inc. All rights reserved.
'' 
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

'' このサンプルでは、利用可能なブレンドモードを使用して2つの画像を合成する方法を紹介します。
'' このサンプルは BlendingModes サンプルと同じ手法を使用していますが、
'' 見栄えの良い結果を生むいくつかのモードだけを示すのではなく、
'' 利用可能なすべてのモードを小さなスケールでデモンストレーションします。
'' ベース画像とブレンド画像は BlendingModes サンプルで使用されているものと同じです。
'' BlendImages_0 および BlendText のサンプルも参照してください。
Public Class AllBlendingModes
    Function GenerateImage(
        ByVal pixelSize As Size,
        ByVal dpi As Single,
        ByVal opaque As Boolean,
        Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
        Using origBmp = New GcBitmap(), spectrumBmp = New GcBitmap()
            '' サンプル画像を読み込みます。
            Dim imagePath = Path.Combine("Resources", "ImagesBis", "orchid.jpg")
            Using stm = New FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)
                origBmp.Load(stm)
            End Using

            '' ブレンドに使用するソースを読み込みます。
            Dim spectrumPath = Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png")
            Using stm = New FileStream(spectrumPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)
                spectrumBmp.Load(stm)

                spectrumBmp.Opaque = opaque
                origBmp.Opaque = opaque

                '' 生成されるビットマップ上に 4 つのサンプルを配置できるよう、
                '' 元の写真をリサイズします。
                Dim w = pixelSize.Width / 4
                Dim h = pixelSize.Height / 4
                Using g = bmp.CreateGraphics()
                    '' 説明文(キャプション)の準備をします。
                    Dim tl = g.CreateTextLayout()
                    tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf"))
                    tl.DefaultFormat.FontSize = 12
                    tl.ParagraphAlignment = ParagraphAlignment.Center
                    tl.TextAlignment = TextAlignment.Center
                    tl.MaxWidth = w
                    tl.MaxHeight = h
                    tl.MarginTop = h - g.MeasureString("QWERTY", tl.DefaultFormat).Height * 1.4F

                    '' 全 16 種類のブレンドモードを 4x4 のグリッド状に描画します。
                    Using sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic),
                            sizedSpectrumBmp = spectrumBmp.Resize(w, h)
                        For row = 0 To 3
                            For col = 0 To 3
                                '' サンプル
                                Dim blendMode = CType(row * 4 + col, BlendMode)
                                Dim x = w * col, y = h * row
                                bmp.BitBlt(sizedBmp, x, y)
                                bmp.CompositeAndBlend(sizedSpectrumBmp, x, y, CompositeMode.SourceOver, blendMode)

                                '' 説明文
                                tl.Clear()
                                tl.Append(blendMode.ToString())
                                tl.PerformLayout(True)
                                Dim rc = tl.ContentRectangle
                                rc.Offset(x, y)
                                rc.Inflate(4, 2)
                                g.FillRectangle(rc, Color.White)
                                g.DrawTextLayout(tl, New PointF(x, y))
                            Next
                        Next
                    End Using
                End Using
            End Using
        End Using
        Return bmp
    End Function
End Class