//// This code is part of Document Solutions for Imaging demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Imaging; namespaceDsImagingWeb.Demos{// This sample takes a color JPEG, converts it to different image types// (such as b/w and grayscale) and creates a multi-frame TIFF from those// images.publicclassImageTypesInTiff {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 ms = newMemoryStream();using (var tw = newGcTiffWriter(ms))using (var bmp = newGcBitmap(path)) {// Using the green channel produces a marginally better result for this photo. // For a much better bi-level image produced by dithering, see DitheringInTiff.using (var f = bmp.ToBilevelBitmap(ColorChannel.Green)) tw.AppendFrame(f);using (var f = bmp.ToGrayscaleBitmap()) tw.AppendFrame(f);// 4bpp allows from 8 to 16 colors, we use max (16):using (var f = bmp.ToIndexed4bppBitmap(16)) tw.AppendFrame(f);// 8bpp allows from 8 to 256 colors, we use max (256):using (var f = bmp.ToIndexed8bppBitmap(256)) tw.AppendFrame(f); tw.AppendFrame(bmp); } ms.Seek(0, SeekOrigin.Begin);return ms; } }}