I
tried this code below and it worked. But the problem is that, the
quality is not good, I can see some colors are not good. I want to
create gif that has good quality of resolution.
* create Gif */
//you should replace filepath
String[] imageFilePaths = new String[] { @"c:\gif\1\1.png", @"c:\gif\2\2.png", @"c:\gif\3\3.png", @"c:\gif\4\4.png", @"c:\gif\5\5.png", @"c:\gif\6\6.png"};
String outputFilePath = "c:\\test.gif";
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.Start( outputFilePath );
e.SetDelay(500);
//-1:no repeat,0:always repeat
e.SetRepeat(0);
for (int i = 0, count = imageFilePaths.Length; i < count; i++ )
{
e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
}
e.Finish();
Please help me this is urgent
* create Gif */
//you should replace filepath
String[] imageFilePaths = new String[] { @"c:\gif\1\1.png", @"c:\gif\2\2.png", @"c:\gif\3\3.png", @"c:\gif\4\4.png", @"c:\gif\5\5.png", @"c:\gif\6\6.png"};
String outputFilePath = "c:\\test.gif";
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.Start( outputFilePath );
e.SetDelay(500);
//-1:no repeat,0:always repeat
e.SetRepeat(0);
for (int i = 0, count = imageFilePaths.Length; i < count; i++ )
{
e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
}
e.Finish();
Please help me this is urgent

Marvin ReidRank #1,963 · 746 reputationPosted Nov 15, 2022, 5:27 PM EST
You can use the RasterCodecs Save method to combine your images into a Gif file. You can then leverage the RasterImageAnimator class to display the gif animation. Here is some sample code and resources for this:
//Merge static void MergeFiles(string[] files, string outputFile) { using (RasterCodecs codecs = new RasterCodecs()) foreach (var file in files) using (RasterImage image = codecs.Load(file)) codecs.Save(image, outputFile, RasterImageFormat.Gif, 0, 1, -1, 1, CodecsSavePageMode.Append); } //Animate private RasterImage FlattenAndReverse(RasterImage inputImage) { int w = inputImage.AnimationGlobalSize.Width, h = inputImage.AnimationGlobalSize.Height; if (w <= 0) w = inputImage.Width; if (h <= 0) h = inputImage.Height; RasterImage renderImage = new RasterImage( RasterMemoryFlags.Conventional, w, h, inputImage.BitsPerPixel, inputImage.Order, inputImage.ViewPerspective, null, IntPtr.Zero, 0); // Copy the palette from the animated image to this newly created image inputImage.CopyPaletteTo(renderImage); RasterImage flatImage = null; // Create the RasterImageAnimator object RasterImageAnimator _animator = new RasterImageAnimator(renderImage, inputImage); // Animate it and save the frames in reverse order // Use GDI+ paint engine to support transparent colors RasterPaintProperties props = _pictureBox.PaintProperties; props.PaintEngine = RasterPaintEngine.GdiPlus; using (RasterImageGdiPlusGraphicsContainer _gdiPlusGraphics = new RasterImageGdiPlusGraphicsContainer(renderImage)) { Graphics g = _gdiPlusGraphics.Graphics; RasterImageAnimatorState state; bool done = false; while (!done) { LeadRect srcRect = new LeadRect(0, 0, renderImage.ImageWidth, renderImage.ImageHeight); LeadRect updateRect; LeadRect destRect; state = _animator.Process(); switch (state) { case RasterImageAnimatorState.WaitDelay: case RasterImageAnimatorState.WaitInputDelay: // Set the animation delay into the last frame that got inserted flatImage.AnimationDelay = _animator.Delay; _animator.CancelWait(); break; case RasterImageAnimatorState.Render: break; case RasterImageAnimatorState.WaitInput: // In case the animated image has the "wait for user input" flags, // Cancel the waiting _animator.CancelWait(); break; case RasterImageAnimatorState.PostRender: // Get the area in the target image that has changed updateRect = _animator.GetUpdateRectangle(true); destRect = new LeadRect(0, 0, renderImage.ImageWidth, renderImage.ImageHeight); // Paint it RasterImagePainter.Paint(renderImage, g, srcRect, updateRect, destRect, destRect, props); if (flatImage == null) flatImage = renderImage.Clone(); else flatImage.InsertPage(0, renderImage.Clone()); // Insert at the beginning to reverse the frames flatImage.Page = 1; // The newly inserted frame is always number 1 flatImage.AnimationDelay = 50; // Set value in case the animation doesn't provide one. break; case RasterImageAnimatorState.End: done = true; // Exist the loop once animation is done break; default: break; } } } return flatImage; }https://www.leadtools.com/help/sdk/tutorials/dotnet-winforms-convert-a-multipage-image-to-reverse-animated-gif.html
https://www.leadtools.com/help/sdk/tutorials/dotnet-console-create-a-multipage-file-from-multiple-images.html
Lalit MRank #1,186 · 1.5K reputationPosted Dec 13, 2009, 7:17 PM EST