Contribution: Gif to Sprite Animation

Need to know how to do something in Gorgon? Got some info on how to do something in Gorgon? Got something that relates to Gorgon but doesn't fit anywhere else? Well now it fits here. Submit!
Forum rules
Try to keep it Gorgon related please.

  • Because gorgon is so awesome i would like to help out making it even better, so i'm going to post some of my functions i made to compliment gorgon.

    Here's a function that takes a gif file and converts it to a Sprite Animation, I'll post more functions when i think they are ready for public use.

    Code: Select all
            public static Sprite LoadGifFile(string sFilePath, string sSpriteName, bool bLooped)
                if (string.IsNullOrEmpty(sFilePath) || !File.Exists(sFilePath)) throw new FileNotFoundException("File not found: " + sFilePath);

                // Create Sprite
                Sprite gifSprite = new Sprite(sSpriteName);

                // Load Gif File
                using (System.Drawing.Image gifImg = System.Drawing.Image.FromFile(sFilePath))
                    FrameDimension dimension = new FrameDimension(gifImg.FrameDimensionsList[0]);
                    PropertyItem item = gifImg.GetPropertyItem(20736);
                    int interval = BitConverter.ToInt32(item.Value, 0)*10;
                    int frames = gifImg.GetFrameCount(FrameDimension.Time);

                    // Create Animation
                    Animation anim = new Animation("GifAnimation", frames*interval);
                    anim.Looped = bLooped;
                    KeyImage imageKeyFrame;

                    // Add Frames to animation
                    for (int i = 0; i < frames; i++)
                        gifImg.SelectActiveFrame(dimension, i);
                        GorgonLibrary.Graphics.Image image = GorgonLibrary.Graphics.Image.FromBitmap(sSpriteName + ".frame" + i, gifImg);
                        imageKeyFrame = new KeyImage(i*interval, image);
                        imageKeyFrame.ImageOffset = new Vector2D(0, 0);
                        imageKeyFrame.ImageSize = new Vector2D(image.Width, image.Height);
                    // Start Animation
                    anim.AnimationState = AnimationState.Playing;

                // return sprite
                return gifSprite;
    User avatar

  • That's awesome. And thank you for the code.

    Hopefully soon I'll actually get some free time to play around with it and include it in the main code base. :(
    haikus are easy
    but sometimes they don't make sense
    User avatar
    Site Admin
    Site Admin
    Posts: 324
    Joined: Wed Feb 27, 2008 9:15 pm
    Location: Canada


Return to General

  • Who is online
  • Users browsing this forum: No registered users and 1 guest