//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Drawing;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Imaging;usingGCTEXT = GrapeCity.Documents.Text;usingGCDRAW = GrapeCity.Documents.Drawing; namespaceDsImagingWeb.Demos{// 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 BlendImages_0 and BlendingModes samples.publicclassBlendText {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] _ = null) {var ispectr = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "spectrum-500x500.png"));constintmargin = 36;constintNCOLS = 4;var w = (int)((pixelSize.Width - margin * 2) / NCOLS);var h = w / 2;int row = 0, col = 0;float bottomy = 0; var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);using (var g = bmp.CreateGraphics(Color.White)) {// Text layout for captions:var tl = g.CreateTextLayout(); tl.DefaultFormat.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMonoBold.ttf")); tl.DefaultFormat.FontSize = 22; tl.ParagraphAlignment = ParagraphAlignment.Center; tl.TextAlignment = TextAlignment.Center; tl.MaxWidth = w; tl.MaxHeight = h; tl.MarginTop = (h - h / 1.4f) / 2; tl.DefaultFormat.ForeColor = Color.Black;var tfWhite = newTextFormat(tl.DefaultFormat) { ForeColor = Color.White }; // Render all blend modes in a grid:var modes = Enum.GetValues(typeof(BlendMode));foreach (var mode in modes) {var blendMode = (BlendMode)mode;if (!g.IsBlendModeSupported(blendMode))continue; int x = margin + w * col;int y = margin + h * row;var r = newRectangleF(x, y, w, h); // Draw spectrum image normally: g.BlendMode = BlendMode.Normal; g.DrawImage(ispectr, r, null, ImageAlign.StretchImage);// Draw blend mode name using the current blend mode: tl.Clear(); tl.AppendLine($"B: {blendMode}"); tl.Append($"W: {blendMode}", tfWhite); tl.PerformLayout(true);var rc = tl.ContentRectangle; rc.Offset(x, y); rc.Inflate(4, 2);// Current blend mode: g.BlendMode = blendMode; g.DrawTextLayout(tl, newPointF(x, y));// Draw spectrum image again using BlendMode.Difference// to produce (mostly) colorful text on black background: g.BlendMode = BlendMode.Difference; g.DrawImage(ispectr, r, null, ImageAlign.StretchImage);// Draw a rectangle to mark the current area: g.BlendMode = BlendMode.Normal; g.DrawRectangle(r, Color.Gray); bottomy = r.Bottom;if (++col == NCOLS) { col = 0; ++row; } }// For reference, draw the backdrop: tl.Clear(); tl.MarginAll = 0; tl.MaxWidth = bmp.PixelWidth; tl.MaxHeight = null; tl.DefaultFormat.FontSize = 14; tl.TextAlignment = TextAlignment.Leading; tl.ParagraphAlignment = ParagraphAlignment.Near; tl.Append("The spectrum image used as the backdrop for the texts above:"); g.DrawTextLayout(tl, newPointF(margin, bottomy + margin)); g.DrawImage(ispectr, newRectangleF(margin, bottomy + margin + tl.ContentHeight + 24, w, w), null, ImageAlign.StretchImage); }return bmp; } }}