⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amigoimage.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace Imps.Utils
{
    using Imps.Client.Utils;
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;

    public class AmigoImage
    {
        protected int _currentCycleCount;
        protected Bitmap _currentImage;
        private int _CurrentIndex;
        protected int _cycleCount;
        protected int _frameCount;
        protected int _frameFrequency;
        protected System.Drawing.Image _image;
        protected bool _isSpeedFirst;
        protected ListCollection<Bitmap> _nodes;
        protected System.Drawing.Image _previewImg;
        protected System.Drawing.Size _size;
        protected byte[] _time;
        protected int _timeSum;

        public AmigoImage()
        {
            this.ClassInitCollection();
        }

        public AmigoImage(bool bIsSpeedFirst)
        {
            this._isSpeedFirst = bIsSpeedFirst;
            this.ClassInitCollection();
        }

        public AmigoImage(System.Drawing.Image image) : this(image, 0)
        {
            this._isSpeedFirst = true;
        }

        public AmigoImage(string FilePath)
        {
            this.ClassInitCollection();
            this.FromFile(FilePath);
        }

        public AmigoImage(System.Drawing.Image image, bool bIsSpeedFirst) : this(image, 0, bIsSpeedFirst)
        {
        }

        public AmigoImage(System.Drawing.Image image, int circles) : this(image, circles, (System.Drawing.Image) null)
        {
            this._isSpeedFirst = true;
        }

        public AmigoImage(string FilePath, bool bIsSpeedFirst)
        {
            this._isSpeedFirst = bIsSpeedFirst;
            this.ClassInitCollection();
            this.FromFile(FilePath);
        }

        public AmigoImage(System.Drawing.Image image, int circles, bool bIsSpeedFirst) : this(image, circles, null, bIsSpeedFirst)
        {
        }

        public AmigoImage(System.Drawing.Image image, int circles, System.Drawing.Image previewImage)
        {
            this.ClassInitCollection();
            this._cycleCount = circles;
            this._image = image;
            this._previewImg = previewImage;
            if (image != null)
            {
                this._currentImage = new Bitmap(image);
            }
            this.ParseImage(image);
        }

        public AmigoImage(System.Drawing.Image image, int circles, System.Drawing.Image previewImage, bool bIsSpeedFirst)
        {
            this._isSpeedFirst = bIsSpeedFirst;
            this.ClassInitCollection();
            this._cycleCount = circles;
            this._image = image;
            this._previewImg = previewImage;
            if (image != null)
            {
                this._currentImage = new Bitmap(image);
            }
            this.ParseImage(image);
        }

        private void ClassInitCollection()
        {
            this._nodes = new ListCollection<Bitmap>();
            this._frameFrequency = 0;
        }

        public AmigoImage Clone()
        {
            return new AmigoImage(this._image, this._cycleCount, this._previewImg);
        }

        public void Dispose(bool bDisposePreviewImg, bool bDisposeImg)
        {
            try
            {
                if (bDisposePreviewImg && (this._previewImg != null))
                {
                    this._previewImg.Dispose();
                    this._previewImg = null;
                }
                if (bDisposeImg && (this._image != null))
                {
                    this._image.Dispose();
                    this._image = null;
                }
                if (this._currentImage != null)
                {
                    this._currentImage.Dispose();
                    this._currentImage = null;
                }
                for (int i = 0; i < this._nodes.Count; i++)
                {
                    this._nodes[i].Dispose();
                }
                this._nodes.Clear();
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        public void FromFile(string FilePath)
        {
            try
            {
                if (File.Exists(FilePath))
                {
                    this._image = System.Drawing.Image.FromFile(FilePath);
                }
            }
            catch
            {
                this._image = null;
                return;
            }
            this.ParseImage(this._image);
        }

        public int GetFrameTime(int frame)
        {
            if (this.FrameCount == 1)
            {
                return 0;
            }
            if (frame > this.FrameCount)
            {
                return -1;
            }
            int num = BitConverter.ToInt32(this._time, frame * this._frameFrequency) * 10;
            if (num < 50)
            {
                return 100;
            }
            return num;
        }

        public bool IsValidImage()
        {
            return (this._image != null);
        }

        public virtual System.Drawing.Image NextFrame(int interval)
        {
            int elapsedTime = -1;
            return this.NextFrame(interval, ref elapsedTime);
        }

        public virtual System.Drawing.Image NextFrame(int interval, ref int elapsedTime)
        {
            if (this.CanPlay && ((this._currentCycleCount < this._cycleCount) || (this._cycleCount <= 0)))
            {
                if (this._image == null)
                {
                    return null;
                }
                try
                {
                    if (elapsedTime != -1)
                    {
                        this._timeSum = elapsedTime;
                        this._timeSum += interval;
                    }
                    else
                    {
                        this._timeSum += interval;
                    }
                    int num = 0;
                    int frame = 0;
                    frame = 0;
                    while (frame < this.FrameCount)
                    {
                        num += this.GetFrameTime(frame);
                        if (num >= this._timeSum)
                        {
                            break;
                        }
                        frame++;
                    }
                    if (frame >= (this.FrameCount - 1))
                    {
                        this._timeSum = 0;
                        frame = this.FrameCount - 1;
                        this._currentCycleCount++;
                    }
                    this._CurrentIndex = frame;
                    if (this.IsSpeedFirst)
                    {
                        if (frame < this._nodes.Count)
                        {
                            this._currentImage = this._nodes[frame];
                        }
                    }
                    else
                    {
                        FrameDimension dimension = new FrameDimension(this._image.FrameDimensionsList[0]);
                        int frameCount = this._image.GetFrameCount(dimension);
                        if (frame < frameCount)
                        {
                            this._image.SelectActiveFrame(dimension, frame);
                            this._currentImage.Dispose();
                            this._currentImage = new Bitmap(this._image);
                        }
                    }
                }
                catch (Exception exception)
                {
                    ClientLogger.WriteException(exception);
                }
                if (elapsedTime != -1)
                {
                    elapsedTime = this._timeSum;
                }
            }
            return this._currentImage;
        }

        private void ParseImage(System.Drawing.Image image)
        {
            this._currentCycleCount = 0;
            this._frameCount = 0;
            if (image != null)
            {
                this._size = image.Size;
                FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
                this._frameCount = image.GetFrameCount(dimension);
                if (this._frameCount > 1)
                {
                    this._frameFrequency = image.PropertyItems[0].Value.GetLength(0) / this.FrameCount;
                    this._time = image.PropertyItems[0].Value;
                    if (this.IsSpeedFirst)
                    {
                        for (int i = 0; i < this._frameCount; i++)
                        {
                            image.SelectActiveFrame(dimension, i);
                            Bitmap item = new Bitmap(image);
                            this._nodes.Add(item);
                        }
                    }
                }
            }
        }

        public void Start()
        {
            this._currentCycleCount = 0;
        }

        public void Stop()
        {
            this._timeSum = 0;
        }

        public bool CanPlay
        {
            get
            {
                if (this._frameCount <= 1)
                {
                    return false;
                }
                if (((this._cycleCount != 0) && (this._currentCycleCount >= this._cycleCount)) && (this._currentCycleCount >= this._cycleCount))
                {
                    this._timeSum = 0;
                    return false;
                }
                return true;
            }
        }

        public Bitmap CurrentImage
        {
            get
            {
                return this._currentImage;
            }
        }

        public int CurrentIndex
        {
            get
            {
                return this._CurrentIndex;
            }
        }

        public int CycleCount
        {
            get
            {
                return this._cycleCount;
            }
        }

        public int FrameCount
        {
            get
            {
                return this._frameCount;
            }
        }

        public IntPtr Hbitmap
        {
            get
            {
                try
                {
                    return this.CurrentImage.GetHbitmap();
                }
                catch
                {
                    return IntPtr.Zero;
                }
            }
        }

        public int Height
        {
            get
            {
                return this._size.Height;
            }
        }

        public System.Drawing.Image Image
        {
            get
            {
                return this._image;
            }
        }

        public ListCollection<Bitmap> Images
        {
            get
            {
                if (!this.IsSpeedFirst)
                {
                    FrameDimension dimension = new FrameDimension(this._image.FrameDimensionsList[0]);
                    this._frameCount = this._image.GetFrameCount(dimension);
                    if (this._frameCount > 1)
                    {
                        this._frameFrequency = this._image.PropertyItems[0].Value.GetLength(0) / this.FrameCount;
                        this._time = this._image.PropertyItems[0].Value;
                        for (int i = 0; i < this._frameCount; i++)
                        {
                            this._image.SelectActiveFrame(dimension, i);
                            Bitmap item = new Bitmap(this._image);
                            this._nodes.Add(item);
                        }
                    }
                }
                return this._nodes;
            }
        }

        public bool IsAnimated
        {
            get
            {
                return (this._frameCount > 1);
            }
        }

        public bool IsSpeedFirst
        {
            get
            {
                return this._isSpeedFirst;
            }
            set
            {
                this._isSpeedFirst = value;
            }
        }

        public System.Drawing.Image PreviewImage
        {
            get
            {
                return (this._previewImg ?? this._image);
            }
        }

        public System.Drawing.Size Size
        {
            get
            {
                return this._size;
            }
        }

        public int Width
        {
            get
            {
                return this._size.Width;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -