//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Text;usingGrapeCity.Documents.Imaging;usingGCTEXT = GrapeCity.Documents.Text; namespaceDsImagingWeb.Demos{// This sample takes a color JPEG, and creates bi-level bitmaps from it// using all available dithering methods. The resulting b/w images// are added as frames to a multi-frame TIFF.// The original color image is added as the last page.publicclassDitheringInTiff {publicstringDefaultMime { get => Common.Util.MimeTypes.TIFF; } publicStreamGenerateImageStream(string targetMime, Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {if (targetMime != Common.Util.MimeTypes.TIFF)thrownewException("This sample only supports TIFF output format."); var path = Path.Combine("Resources", "Images", "minerva.jpg");var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeMono.ttf"));var ms = newMemoryStream();using (var tw = newGcTiffWriter(ms))using (var bmp = newGcBitmap(path)) {// Create text layout for labels:var tl = newTextLayout(bmp.DpiX); tl.DefaultFormat.Font = font; tl.DefaultFormat.FontSize = 16; tl.DefaultFormat.BackColor = Color.White;// Loop through all dithering methods (starting with no dithering):var methods = typeof(DitheringMethod).GetEnumValues();foreach (DitheringMethod method in methods) {using (var tbmp = bmp.Clone()) {// Apply dithering: tbmp.ApplyEffect(DitheringEffect.Get(method));// Draw label: tl.Clear(); tl.Append(method.ToString()); tl.PerformLayout(true);using (var g = tbmp.CreateGraphics()) g.DrawTextLayout(tl, newPointF(0, tbmp.Height - tl.ContentHeight));// Convert to bi-level bitmap:using (var f = tbmp.ToBilevelBitmap()) tw.AppendFrame(f); } }// Add original image: tw.AppendFrame(bmp); } ms.Seek(0, SeekOrigin.Begin);return ms; } }}