'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.NumericsImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing '' This sample demonstrates composing two images using a few'' of the many available blending modes.'' The base image is a photo of a white orchid on a dark background.'' The blended image is a simple spectrum (thumbnail shown in the bottom right corner).'' See the AllBlendingModes sample for a demo of all available blending modes.PublicClassBlendingModesFunctionGenerateImage(ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,OptionalByVal sampleParams AsString() = Nothing) AsGcBitmap Dim bmp = NewGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)Using origBmp = NewGcBitmap(), spectrumBmp = NewGcBitmap()'' Load a sample photo:Dim imagePath = Path.Combine("Resources", "ImagesBis", "orchid.jpg")Using stm = NewFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess) origBmp.Load(stm)EndUsing '' Blending source:Dim spectrumPath = Path.Combine("Resources", "ImagesBis", "spectrum-500x500.png")Using stm = NewFileStream(spectrumPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess) spectrumBmp.Load(stm)EndUsing origBmp.Opaque = opaque spectrumBmp.Opaque = opaque '' Resize the original photo so we can place 4 samples of it'' on the resulting bitmap:Dim w = pixelSize.Width / 2Dim h = pixelSize.Height / 2Using sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic), sizedSpectrumBmp = spectrumBmp.Resize(w, h)'' Resized original image: bmp.BitBlt(sizedBmp, 0, 0) '' Blending mode Color bmp.BitBlt(sizedBmp, w, 0) bmp.CompositeAndBlend(sizedSpectrumBmp, w, 0, CompositeMode.SourceOver, BlendMode.Color) '' Blending mode SoftLight bmp.BitBlt(sizedBmp, 0, h) bmp.CompositeAndBlend(sizedSpectrumBmp, 0, h, CompositeMode.SourceOver, BlendMode.SoftLight) '' Blending mode Hue bmp.BitBlt(sizedBmp, w, h) bmp.CompositeAndBlend(sizedSpectrumBmp, w, h, CompositeMode.SourceOver, BlendMode.Hue)EndUsing'' Show a thumbnail of the blend source in the bottom right cornerUsing spectrumThumbnail = spectrumBmp.Resize(w / 4, h / 4) bmp.BitBlt(spectrumThumbnail, pixelSize.Width - spectrumThumbnail.PixelWidth, pixelSize.Height - spectrumThumbnail.PixelHeight)EndUsing'' Add borders between the quadrants, And captions for each:Dim lineh = 2Using g = bmp.CreateGraphics(Nothing)Dim foreColor = Color.YellowDim backColor = Color.BlueDim fnt = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf")) g.DrawLine(w, 0, w, h * 2, NewGCDRAW.Pen(Color.Gray, lineh * 2)) g.DrawLine(0, h, w * 2, h, NewGCDRAW.Pen(Color.Gray, lineh * 2))Dim tf = NewTextFormat() With {.Font = fnt, .FontSize = 18, .ForeColor = foreColor, .BackColor = backColor, .FontBold = True}Dim th = g.MeasureString("QWERTY", tf).Height g.DrawString(" Original image ", tf, NewPointF(0, h - th + lineh)) g.DrawString(" BlendMode.Color ", tf, NewPointF(w + lineh, h - th + lineh)) g.DrawString(" BlendMode.SoftLight ", tf, NewPointF(0, h * 2 + lineh - th + lineh)) g.DrawString(" BlendMode.Hue ", tf, NewPointF(w + lineh, h * 2 + lineh - th + lineh))EndUsingEndUsingReturn bmpEndFunctionEndClass