//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingSystem.Collections.Generic;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 BlendText and BlendingModes samples.publicclassBlendImages {conststringc_keyOrchid = "orchid";conststringc_keySpectrum = "spectrum"; publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {var iorchid = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "orchid.jpg"));var ispectr = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png"));GCDRAW.Image ifore, iback;if (sampleParams[3] == c_keyOrchid) { ifore = iorchid; iback = ispectr; }else// c_keyOrchid { ifore = ispectr; iback = iorchid; }constintmargin = 36;constintNCOLS = 4;var w = (int)((pixelSize.Width - margin * 2) / NCOLS);var h = (int)((iorchid.Height * w) / iorchid.Width);int row = 0, col = 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", "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: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); g.BlendMode = BlendMode.Normal; g.DrawImage(iback, r, null, ImageAlign.StretchImage); g.BlendMode = blendMode; g.DrawImage(ifore, r, null, ImageAlign.StretchImage); g.BlendMode = BlendMode.Normal; // Caption: tl.Clear(); tl.Append(blendMode.ToString()); tl.PerformLayout(true);var rc = tl.ContentRectangle; rc.Offset(x, y); rc.Inflate(4, 2); g.FillRectangle(rc, Color.White); g.DrawTextLayout(tl, newPointF(x, y));if (++col == NCOLS) { col = 0; ++row; } } }return bmp; } publicstaticList<string[]> GetSampleParamsList() {returnnewList<string[]>() {// Strings are name, description, info. Rest are arbitrary strings:newstring[] { "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 },newstring[] { "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 }, }; } }}