예제 #1
0
        /// <param name="filename">Animated Image (ie: animated gif).</param>
        public static AnimatedImageData GetAnimatedImageData(string fileName)
        {
            int index = AnimatedImageDataFileNames.IndexOf(fileName);

            if (index >= 0)
            {
                // AnimatedImageData Already Exists
                // move it to the end of the array and return it
                AnimatedImageData data = AnimatedImageDatas[index];
                string name = AnimatedImageDataFileNames[index];

                AnimatedImageDatas.RemoveAt(index);
                AnimatedImageDataFileNames.RemoveAt(index);
                AnimatedImageDatas.Add(data);
                AnimatedImageDataFileNames.Add(name);

                return AnimatedImageDatas[AnimatedImageDatas.Count-1];
            }
            else
            {
                // New AnimatedImageData
                System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);
                AnimatedImageData data = new AnimatedImageData();

                //// Get Frame Duration
                System.Drawing.Imaging.PropertyItem frameDelay = image.GetPropertyItem(0x5100);
                int frameDuration = (frameDelay.Value[0] + frameDelay.Value[1] * 256) * 10;
                if (frameDuration > 10)
                    data.FrameDuration = frameDuration;
                else
                    data.FrameDuration = AnimatedImage.DEFAULT_FRAME_DURATION;

                //// Store AnimatedImageData
                AnimatedImageDatas.Add(data);
                AnimatedImageDataFileNames.Add(fileName);

                // Limit amount of Animations in Memory
                if (AnimatedImageDatas.Count >= MAX_ANIMATIONS)
                {
                    for (int i = 0; i < AnimatedImageDatas[0].Frames.Count; i++)
                        AnimatedImageDatas[0].Frames[i].Dispose();

                    AnimatedImageDatas.RemoveAt(0);
                    AnimatedImageDataFileNames.RemoveAt(0);
                }

                //// Get Frames
                LoadingAnimatedImage loadingAnimatedImage = new LoadingAnimatedImage(image, data);
                Thread loadFramesThread = new Thread(new ThreadStart(loadingAnimatedImage.LoadFrames));
                loadFramesThread.IsBackground = true;
                loadFramesThread.Start();

                while (data.Frames.Count <= 0); // wait for at least one frame to be loaded

                return data;
            }
        }
예제 #2
0
        public AnimatedImage(AnimatedImageData data)
        {
            Data = data;

            Sprite = new Sprite(data.Frames[0]);
            AddChild(Sprite);

            CurrentTime        = 0;
            CurrentFrameLength = data.FrameDuration;
        }
예제 #3
0
        public AnimatedImage(AnimatedImageData data)
        {
            Data = data;

            Sprite = new Sprite(data.Frames[0]);
            AddChild(Sprite);

            CurrentTime = 0;
            CurrentFrameLength = data.FrameDuration;
        }
예제 #4
0
파일: ImageViewer.cs 프로젝트: arxae/vimage
        /// <summary>Loads an image into memory but doesn't set it as the displayed image.</summary>
        private bool PreloadImage(string fileName)
        {
            if (ImageViewerUtils.GetExtension(fileName).Equals("gif"))
            {
                // Animated Image
                AnimatedImageData image = Graphics.GetAnimatedImageData(fileName);
            }
            else
            {
                // Image
                Texture texture = Graphics.GetTexture(fileName);
                if (texture == null)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #5
0
 public LoadingAnimatedImage(System.Drawing.Image image, AnimatedImageData data)
 {
     Image = image;
     Data  = data;
 }
예제 #6
0
        /// <param name="filename">Animated Image (ie: animated gif).</param>
        public static AnimatedImageData GetAnimatedImageData(string fileName)
        {
            lock (AnimatedImageDatas)
            {
                int index = AnimatedImageDataFileNames.IndexOf(fileName);

                if (index >= 0)
                {
                    // AnimatedImageData Already Exists
                    // move it to the end of the array and return it
                    AnimatedImageData data = AnimatedImageDatas[index];
                    string            name = AnimatedImageDataFileNames[index];

                    AnimatedImageDatas.RemoveAt(index);
                    AnimatedImageDataFileNames.RemoveAt(index);
                    AnimatedImageDatas.Add(data);
                    AnimatedImageDataFileNames.Add(name);

                    return(AnimatedImageDatas[AnimatedImageDatas.Count - 1]);
                }
                else
                {
                    // New AnimatedImageData
                    System.Drawing.Image image = System.Drawing.Image.FromFile(fileName);
                    AnimatedImageData    data  = new AnimatedImageData();

                    //// Get Frame Duration
                    int frameDuration = 0;
                    try
                    {
                        System.Drawing.Imaging.PropertyItem frameDelay = image.GetPropertyItem(0x5100);
                        frameDuration = (frameDelay.Value[0] + frameDelay.Value[1] * 256) * 10;
                    }
                    catch { }
                    if (frameDuration > 10)
                    {
                        data.FrameDuration = frameDuration;
                    }
                    else
                    {
                        data.FrameDuration = AnimatedImage.DEFAULT_FRAME_DURATION;
                    }

                    //// Store AnimatedImageData
                    AnimatedImageDatas.Add(data);
                    AnimatedImageDataFileNames.Add(fileName);

                    // Limit amount of Animations in Memory
                    if (AnimatedImageDatas.Count > MAX_ANIMATIONS)
                    {
                        AnimatedImageDatas[0].CancelLoading = true;
                        for (int i = 0; i < AnimatedImageDatas[0].Frames.Count; i++)
                        {
                            AnimatedImageDatas[0]?.Frames[i]?.Dispose();
                        }
                        AnimatedImageDatas.RemoveAt(0);
                        AnimatedImageDataFileNames.RemoveAt(0);
                    }

                    //// Get Frames
                    LoadingAnimatedImage loadingAnimatedImage = new LoadingAnimatedImage(image, data);
                    Thread loadFramesThread = new Thread(new ThreadStart(loadingAnimatedImage.LoadFrames));
                    loadFramesThread.Name         = "AnimationLoadThread - " + fileName;
                    loadFramesThread.IsBackground = true;
                    loadFramesThread.Start();

                    while (data.Frames.Count <= 0)
                    {
                        ;                            // wait for at least one frame to be loaded
                    }
                    return(data);
                }
            }
        }
예제 #7
0
 public LoadingAnimatedImage(System.Drawing.Image image, AnimatedImageData data)
 {
     Image = image;
     Data = data;
 }