BlendImages.vb
C# VB
'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.IOImports System.DrawingImports GrapeCity.Documents.DrawingImports GrapeCity.Documents.TextImports GrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing
'' This sample demonstrates the effects of different blend modes'' when drawing on a GcGraphics. Note that the current blend mode'' set on an instance of GcGraphics (including GcBitmapGraphics)'' affects not only images but all drawing operations.'' See also BlendText and BlendingModes samples.Public Class BlendImages Private Const c_keyOrchid As String = "orchid" Private Const c_keySpectrum As String = "spectrum"
Public Function GenerateImage( ByVal pixelSize As Size, ByVal dpi As Single, ByVal opaque As Boolean, Optional ByVal sampleParams As String() = Nothing) As GcBitmap
Dim iorchid = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "orchid.jpg")) Dim ispectr = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png")) Dim ifore As GCDRAW.Image, iback As GCDRAW.Image
If sampleParams IsNot Nothing AndAlso sampleParams.Length > 3 AndAlso sampleParams(3) = c_keyOrchid Then ifore = iorchid iback = ispectr Else ifore = ispectr iback = iorchid End If
Const margin As Integer = 36 Const NCOLS As Integer = 4 Dim w As Integer = CInt((pixelSize.Width - margin * 2) / NCOLS) Dim h As Integer = CInt((iorchid.Height * w) / iorchid.Width) Dim row As Integer = 0, col As Integer = 0
Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi) Using g = bmp.CreateGraphics(Color.White) '' Text layout for captions: 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
'' Render all blend modes in a grid: For Each modeObj In System.Enum.GetValues(GetType(BlendMode)) Dim blendMode = CType(modeObj, BlendMode) If Not g.IsBlendModeSupported(blendMode) Then Continue For
Dim x As Integer = margin + w * col Dim y As Integer = margin + h * row Dim r As New RectangleF(x, y, w, h)
g.BlendMode = BlendMode.Normal g.DrawImage(iback, r, Nothing, ImageAlign.StretchImage) g.BlendMode = blendMode g.DrawImage(ifore, r, Nothing, ImageAlign.StretchImage) g.BlendMode = BlendMode.Normal
'' Caption: 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))
col += 1 If col = NCOLS Then col = 0 row += 1 End If Next End Using
Return bmp End Function
Public Shared Function GetSampleParamsList() As List(Of String()) Return New List(Of String()) From { New String() { "Blend Orchid", "Draw the orchid image over the spectrum image using all supported blend modes", "We draw the tiles in this image by composing two images (an orchid and a spectrum) using the " & "different blend modes supported by GcBitmapGraphics. " & "The spectrum image is drawn using BlendMode.Normal, then the current blend mode on GcBitmapGraphics " & "is set to one of the supported blend modes, and the orchid image is drawn using it. " & "The name of the used blend mode is shown below each tile." & "Note that the blend mode set on the graphics affects not only images but any drawing on this graphics. ", c_keyOrchid }, New String() { "Blend Spectrum", "Draw the spectrum image over the orchid image using all supported blend modes", "We draw the tiles in this image by composing two images (a spectrum and an orchid) using the " & "different blend modes supported by GcBitmapGraphics. " & "The orchid image is drawn using BlendMode.Normal, then the current blend mode on GcBitmapGraphics " & "is set to one of the supported blend modes, and the spectrum image is drawn using it. " & "The name of the used blend mode is shown below each tile." & "Note that the blend mode set on the graphics affects not only images but any drawing on this graphics. ", c_keySpectrum } } End FunctionEnd Class