//// 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 loads an existing GIF and modifies its frames.// Specifically, it applies a color matrix to change the colors,// and flips the images horizontally. // The GIF loaded in this sample is the one produced by IndexedGif.publicclassUpdateGif {publicstringDefaultMime { get => Common.Util.MimeTypes.GIF; } publicStreamGenerateImageStream(string targetMime, Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) {if (targetMime != Common.Util.MimeTypes.GIF)thrownewException("This sample only supports GIF output format."); // Matrix to change colors to greenish blues:var colorMatrix = newColorMatrix5x4() {M11 = 0.2f,M12 = 0.3f,M22 = 0.5f }; var ms = newMemoryStream();// Read source GIF, write modified one (change palette and flip and rotate frames):using (var gr = newGcGifReader(Path.Combine("Resources", "Gifs", "goldfish-indexed.gif")))using (var gw = newGcGifWriter(ms)) {var pal = gr.GetGlobalPalette();// This sample will only work with GIFs that have a global palette:if (pal == null)thrownewException("Source GIF does not have a global palette.");// Use color matrix to update the palette:using (var palBmp = newGcBitmap(pal, pal.Length, 1, true)) palBmp.ApplyColorMatrix(colorMatrix); // Set target palette and other properties: gw.GlobalPalette = pal; gw.LogicalScreenWidth = gr.LogicalScreenWidth; gw.LogicalScreenHeight = gr.LogicalScreenHeight; gw.PixelAspectRatio = gr.PixelAspectRatio; gw.AllowAddingTransparentColor = false;using (var tbmp = newGcBitmap())for (int i = 0; i < gr.Frames.Count; i++) {var frame = gr.Frames[i]; frame.ToGcBitmap(tbmp, i - 1); // Flip the image horizontally (this will reverse the 'rotation' of the fish):using (var bmp = tbmp.FlipRotate(FlipRotateAction.FlipHorizontal)) {// Apply the color matrix and append the frame to the target GIF: bmp.ApplyColorMatrix(colorMatrix); gw.AppendFrame(bmp, pal, DitheringMethod.NoDithering, 0, 0, GifDisposalMethod.DoNotDispose, frame.DelayTime, false); } } } ms.Seek(0, SeekOrigin.Begin);return ms; } }}