//// 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;usingDsImagingWeb.Demos.Common; namespaceDsImagingWeb.Demos{// This sample loads an existing GIF with true color frames // (produced by the MakeGif sample) and converts its frames// to indexed 8bpp images. It also adds a global palette to the// resulting GIF (the palette is taken from the first frame).publicclassIndexedGif {publicstringDefaultMime { get => Common.Util.MimeTypes.GIF; } publicStreamGenerateImageStream(string targetMime, Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {if (targetMime != Util.MimeTypes.GIF)thrownewException("This sample only supports GIF output format."); var ms = newMemoryStream();// Read frames from the source GIF, convert them to 8bpp and save in the target GIF:using (var gr = newGcGifReader(Path.Combine("Resources", "Gifs", "goldfish.gif")))using (var gw = newGcGifWriter(ms)) {for (int i = 0; i < gr.Frames.Count; ++i) {// Add a global palette to the target GIF based on the first frame:if (i == 0)using (var tbmp = gr.Frames[i].ToGcBitmap()) gw.GlobalPalette = tbmp.GenerateOctreePalette(256); var indexedBmp = gr.Frames[i].ReadAsIndexed8bppBitmap(); gw.AppendFrame(indexedBmp, 0, 0, GifDisposalMethod.DoNotDispose, 16); } } ms.Seek(0, SeekOrigin.Begin);return ms; } }}