'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsSystem.NumericsImportsGrapeCity.Documents.DrawingImportsGrapeCity.Documents.TextImportsGrapeCity.Documents.Imaging '' 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.PublicClassUpdateGifFunctionGenerateImageStream(ByVal targetMime AsString,ByVal pixelSize AsSize,ByVal dpi AsSingle,ByVal opaque AsBoolean,Optional sampleParams AsString() = Nothing) AsStream IfNot targetMime = MimeTypes.GIF ThenThrowNew Exception("This sample only supports GIF output format.")EndIf '' Matrix to change colors to greenish blues:Dim colorMatrix = NewColorMatrix5x4() With { .M11 = 0.2F, .M12 = 0.3F, .M22 = 0.5F } Dim ms = NewMemoryStream()'' Read source GIF, write modified one (change palette And flip And rotate frames)Using gr = NewGcGifReader(Path.Combine("Resources", "Gifs", "goldfish-indexed.gif")), gw = NewGcGifWriter(ms) Dim pal = gr.GetGlobalPalette()'' This sample will only work with GIFs that have a global paletteIf pal IsNothingThenThrowNew Exception("Source GIF does not have a global palette.")EndIf'' Use color matrix to update the paletteUsing palBmp = NewGcBitmap(pal, pal.Length, 1, True) palBmp.ApplyColorMatrix(colorMatrix)EndUsing '' Set target paletter And other properties gw.GlobalPalette = pal gw.LogicalScreenWidth = gr.LogicalScreenWidth gw.LogicalScreenHeight = gr.LogicalScreenHeight gw.PixelAspectRatio = gr.PixelAspectRatio gw.AllowAddingTransparentColor = FalseUsing tbmp = NewGcBitmap()For i = 0To gr.Frames.Count - 1Dim frame = gr.Frames(i) frame.ToGcBitmap(tbmp, i - 1) '' Flip the image horizontally (this will reverse the 'rotation' of the fish):Using 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)EndUsingNextEndUsingEndUsing ms.Seek(0, SeekOrigin.Begin)Return msEndFunction PublicReadOnlyPropertyDefaultMime() AsStringGetReturn MimeTypes.GIFEndGetEndPropertyEndClass