示例#1
0
        /// <summary>
        /// Create an image from an image that has a bunch of frames in the one image.
        /// Start at the specified position (Start), and grab Count items (if we can find them)
        /// </summary>
        /// <param name="Count">The number of frames to grab</param>
        /// <param name="Start">A point in the image where we start capturing frames</param>
        /// <param name="Smart_Image">The smart image this is part of</param>
        /// <param name="SpriteImage">the image we use for the sprite.  Should have lots of images as a part of it.</param>
        /// <param name="width">the width of each frame</param>
        /// <param name="height">the height of each frame</param>
        /// <param name="duration">The duration in miliseconds for this frame</param>
        internal Animation(Point Start, SmartImage Smart_Image, Image SpriteImage, int width, int height, int duration, int Count)
        {
            //We create a new animation number for this new animation
            AnimationID = Smart_Image.AnimationCount;

            //Now, we make new frames for each image we can find.
            int x       = Start.X;
            int y       = Start.Y;
            int counter = 0;

            Rectangle where;
            Image newImage;

            while (y + height <= SpriteImage.Height)
            {
                while (x + width <= SpriteImage.Width)
                {
                    where = new Rectangle(x, y, width, height);
                    Bitmap tImage = (Bitmap)SpriteImage;
                    newImage = (Bitmap)tImage.Clone(where, tImage.PixelFormat);
                    AnimationSingleFrame newSingle = new AnimationSingleFrame(newImage, Smart_Image.FrameCount);
                    AnimationFrame       newFrame  = new AnimationFrame(Smart_Image.FrameCount, TimeSpan.FromMilliseconds(duration));
                    Frames.Add(newFrame);
                    Smart_Image.AddFrame(newSingle);
                    x += width;
                    counter++;
                    if (counter >= Count)
                    {
                        return; //Stop when we have reached Count of them
                    }
                }
                y += height;
                x  = 0;
            }
        }
示例#2
0
        internal Animation(SmartImage Smart_Image, int AnimationToCopy, int DegreesOfRotation)
        {
            //We create a new animation number for this new animation
            AnimationID = Smart_Image.AnimationCount;

            GraphicsUnit tUnit = GraphicsUnit.Pixel;
            Animation    One   = Smart_Image.getAnimation(AnimationToCopy);
            Image        MeImage;

            for (int i = 0; i < One.Frames.Count; i++)
            {
                AnimationFrame       AF  = Smart_Image.GetAnimationFrame(AnimationToCopy, i);
                AnimationSingleFrame ASF = Smart_Image.GetSingleFrame(AnimationToCopy, i);
                MeImage = ASF.Frame;
                TimeSpan Duration     = AF.Duration;
                Image    rotatedImage = new Bitmap(MeImage.Width, MeImage.Height);
                using (Graphics g = Graphics.FromImage(rotatedImage))
                {
                    g.TranslateTransform(MeImage.Width / 2, MeImage.Height / 2);                                  //set the rotation point as the center into the matrix
                    g.RotateTransform(DegreesOfRotation * -1);                                                    //rotate.  The rotation direction we use is opposite of what they use
                    g.TranslateTransform(-MeImage.Width / 2, -MeImage.Height / 2);                                //restore rotation point into the matrix
                    g.DrawImage(MeImage, MeImage.GetBounds(ref tUnit), rotatedImage.GetBounds(ref tUnit), tUnit); //draw the image on the new bitmap
                }
                //GC.Collect();
                MeImage = rotatedImage;

                AnimationSingleFrame newSingle = new AnimationSingleFrame(MeImage, Smart_Image.FrameCount);
                AnimationFrame       newFrame  = new AnimationFrame(Smart_Image.FrameCount, Duration);
                Frames.Add(newFrame);
                Smart_Image.AddFrame(newSingle);
            }
        }
示例#3
0
        internal Animation(SmartImage Smart_Image, int AnimationToCopy, bool MirrorHorizontally, bool MirrorVertically)
        {
            //We create a new animation number for this new animation
            AnimationID = Smart_Image.AnimationCount;

            Animation One = Smart_Image.getAnimation(AnimationToCopy);
            Image     MeImage;

            for (int i = 0; i < One.Frames.Count; i++)
            {
                AnimationFrame       AF  = Smart_Image.GetAnimationFrame(AnimationToCopy, i);
                AnimationSingleFrame ASF = Smart_Image.GetSingleFrame(AnimationToCopy, i);
                MeImage = ASF.Frame;
                TimeSpan Duration    = AF.Duration;
                Image    MirrorImage = new Bitmap(MeImage);
                if (MirrorHorizontally)
                {
                    MirrorImage.RotateFlip(RotateFlipType.RotateNoneFlipX);
                }
                if (MirrorVertically)
                {
                    MirrorImage.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }
                //GC.Collect();
                MeImage = MirrorImage;

                AnimationSingleFrame newSingle = new AnimationSingleFrame(MeImage, Smart_Image.FrameCount);
                AnimationFrame       newFrame  = new AnimationFrame(Smart_Image.FrameCount, Duration);
                Frames.Add(newFrame);
                Smart_Image.AddFrame(newSingle);
            }
        }
示例#4
0
        //The simplest case.  It is just one image.  No animation.
        public Animation(SmartImage Smart_Image, Image SpriteImage)
        {
            //We create a new frame for it and make an animation of just one frame
            AnimationID = Smart_Image.AnimationCount;
            AnimationSingleFrame newSingle = new AnimationSingleFrame(SpriteImage, Smart_Image.FrameCount);
            AnimationFrame       newFrame  = new AnimationFrame(Smart_Image.FrameCount, TimeSpan.FromMilliseconds(500));

            Frames.Add(newFrame);
            Smart_Image.AddFrame(newSingle);
        }
示例#5
0
 public void AddFrame(AnimationSingleFrame ToAdd)
 {
     Frames.Add(ToAdd);
 }