スキップしてメイン コンテンツに移動

投稿

C#: Extract Gif Frame Images From an Animated Gif Image

I wrote the post for extracting gif frame image from an animated gif image in Java - Java: Extract Gif Images From An Animated Gif Image . In this post, I have tried to do same thing in C# as well :D Code using System.Drawing; using System.Drawing.Imaging; namespace Utility { public class GifImageUtils { public static void SaveAnimatedGifFrames(string path, string outDir) { var gifImg = Image.FromFile(path); var dimension = new FrameDimension(gifImg.FrameDimensionsList[0]); int frameCount = gifImg.GetFrameCount(dimension); for (int i = 0; i < frameCount; i++) { gifImg.SelectActiveFrame(dimension, i); // create a frame image from the original source image - clone is mandatory var frame = (Image)gifImg.Clone(); frame.Save(outDir+"/"+i+".gif", ImageFormat.Gif); } } } } Exa

C#: Create Indexed PNG Using System.Windows.Media.BitmapSource with Pre-defined Palettes in BitmapPalettes Class

Creating Indexed PNG in C# In C#, there are mainly two namespaces to creating image... System.Drawing namespace System.Windows.Media namespace I've already written the post for creating indexed png using System.Drawing namespace classes - Create Indexed PNG Using C# .Net . So, in this post, I will show you how to create indexed png using classes under System.Windows.Media namespace. Preparation for Using Classes Under System.Windows.Media You need to add following dlls to your project reference in order to handle images using classes under System.Windows.Media. PresentationCore.dll Xaml.dll WindowsBase.dll Creating Palette Based Indexed Image If you would like to create indexed png, first of all, you should create color palette which can hold max 256 colors. Creating color palette is trivial. Please see the below example code: var colors = new List<Color>(); colors.Add(Color.FromRgb(255, 0, 0)); // 0 - red colors.Add(Color.FromRgb(0, 255, 0)); // 1 -

Java: Extract Gif Images From an Animated Gif Image

In this post, I will show you the code for extracting gif frame images from an animated gif image. I will show you two types of code: Simply extracting gif images stored in the original animated gif image Creating gif image by rendering and accumulating each gif frames stored in the original gif image Code for Extracting Gif Image From An Animated Gif Java Code package com.dukesoftware.utils.image; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; public class GifImageUtils { public static void main(String[] args) throws IOException { String sourceGif = "c:/temp/SmallFullColourGIF.gif"; saveAnimatedGifFramePartsToImage(sourceGif, "c:/temp/gif_parts"); } public static void saveAnimatedGifFramePartsToImage(String input, String outDir) throws IOException { ImageReade