//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Drawing;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Imaging;usingGCTEXT = GrapeCity.Documents.Text; namespaceDsImagingWeb.Demos{// This sample demonstrates composing two images using the available blending modes. // The sample uses the same approach as the BlendingModes sample,// but instead of showing a few of the available modes that produce// a nice looking result, demonstrates all of them in smaller scale. // The base and the blended images used as the same as in the BlendingModes sample. // See also BlendImages_0 and BlendText samples.publicclassAllBlendingModes {publicGcBitmapGenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {var bmp = newGcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi);using (var origBmp = newGcBitmap())using (var spectrumBmp = newGcBitmap()) {// Load a sample photo:var imagePath = Path.Combine("Resources", "ImagesBis", "orchid.jpg");using (var stm = newFileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)) origBmp.Load(stm); // Blending source:var spectrumPath = Path.Combine("Resources", "ImagesBis", "spectrum-pastel-500x500.png");using (var stm = newFileStream(spectrumPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.RandomAccess)) spectrumBmp.Load(stm); origBmp.Opaque = spectrumBmp.Opaque = opaque; // Resize the original photo so we can place 4 samples of it// on the resulting bitmap:int w = pixelSize.Width / 4;int h = pixelSize.Height / 4;using (var g = bmp.CreateGraphics()) {// Prepare 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 16 blending modes in a 4x4 grid:using (var sizedBmp = origBmp.Resize(w, h, InterpolationMode.Cubic))using (var sizedSpectrumBmp = spectrumBmp.Resize(w, h)) {for (int row = 0; row < 4; ++row)for (int col = 0; col < 4; ++col) {// Sample:var blendMode = (BlendMode)(row * 4 + col);int x = w * col, y = h * row; bmp.BitBlt(sizedBmp, x, y); bmp.CompositeAndBlend(sizedSpectrumBmp, x, y, CompositeMode.SourceOver, blendMode);// 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)); } } } }return bmp; } }}