コード例 #1
0
        /// <summary>
        /// 释放资源
        /// </summary>
        public void Dispose()
        {
            if (animator != null)
            {
                animator.Transformed -= TransformedEvent;
                animator.Stop();
                animator = null;
            }

            //lock (disposeObj)
            //{
            if (gifDecoder != null)
            {
                int size = gifDecoder.GetFrameCount();
                for (int i = 0; i < size; i++)
                {
                    gifDecoder.GetFrame(i).Dispose();
                }
                gifDecoder = null;
            }

            if (gifEncoder != null)
            {
                gifEncoder.Finish();
                isStart    = false;
                gifEncoder = null;
            }

            if (brushTool != null)
            {
                brushTool.Dispose();
                brushTool = null;
            }

            if (bitmap != null)
            {
                isDisposed = true;
                bitmap.Dispose();
                bitmap = null;
            }

            if (nenoGifImg != null)
            {
                nenoGifImg.Dispose();
                nenoGifImg = null;
            }
            //}
        }
コード例 #2
0
        /// <summary>
        /// 根据动画配置创建动画效果
        /// </summary>
        /// <param name="g"></param>
        public void CreateAnimation(Graphics g1)
        {
            if (animator != null)
            {
                animator.Transformed -= TransformedEvent;
                animator.Stop();
            }

            if (screens != null)
            {
                screens.Clear();
            }

            //List<AnimationChar> chars = new List<AnimationChar>();
            // 创建位图
            bitmap              = new Bitmap(AnimationConfig.Width, AnimationConfig.Height);
            isDisposed          = false;
            g                   = Graphics.FromImage(bitmap);
            g.TextRenderingHint = textRenderingHint;
            g.SmoothingMode     = smoothingMode;

            // 动画创建工厂
            //SetAnimation(g);
            if (animationFactory == null)
            {
                animationFactory = new AnimationFactory(g);
            }
            else
            {
                animationFactory.Graphiscs = g;
            }

            isParallelAnimation = false;
            screens             = animationFactory.CreateAnimationChars(ref isParallelAnimation);// 创建动画
            screenindex         = 0;

            // 动画执行器
            animator              = new StringAnimator(config, isParallelAnimation);
            animator.Screens      = screens;
            animator.Transformed += TransformedEvent;

            //gif 编码器。用于生产gif图片
            gifEncoder = new AnimatedGifEncoder();
            if (AnimationConfig.IsUseGif)
            {
                int delay = (int)(100 / AnimationConfig.AnimationSpeedFactor);
                //if (delay > 500) delay = 500;
                //if (delay < 20) delay = 20;
                gifEncoder.SetDelay(delay);
            }
            else
            {
                gifEncoder.SetDelay(StringAnimator.TIME_INTERVAL);
            }
            gifEncoder.SetRepeat(0);

            if (frog == null)
            {
                try
                {
                    frog    = new Image[5];
                    frog[0] = Bitmap.FromFile("Res/frog1.png");
                    frog[1] = Bitmap.FromFile("Res/frog2.png");
                    frog[2] = Bitmap.FromFile("Res/frog3.png");
                    frog[3] = Bitmap.FromFile("Res/frog4.png");
                    frog[4] = Bitmap.FromFile("Res/frog5.png");
                }
                catch (System.IO.FileNotFoundException) { frog = null; }
                catch (System.OutOfMemoryException) { frog = null; }
                catch (System.ArgumentException) { frog = null; }
            }
            frogIndex = 0;

            // 笔刷工具
            brushTool = new BrushTool();
            brushTool.InitBrush();

            // 获取霓虹背景
            if (AnimationConfig.NeonBackgroundEnabled && AnimationConfig.NenoBackgroundPath.Length > 0)
            {
                //NenoGifPath = AnimationConfig.NenoBackgroundPath;
                nenoGifImg = null;
                try
                {
                    nenoGifImg    = Image.FromFile(AnimationConfig.NenoBackgroundPath);
                    fd            = new FrameDimension(nenoGifImg.FrameDimensionsList[0]);
                    gifFrameIndex = 0;
                }
                catch (System.IO.FileNotFoundException) { }
                catch (System.OutOfMemoryException) { }
                catch (System.ArgumentException) { }
            }
            else
            {
                if (nenoGifImg != null)
                {
                    nenoGifImg.Dispose();
                }
                nenoGifImg    = null;
                gifFrameIndex = -1;
            }

            // 位图保存工具
            if (AnimationConfig.IsUseGif)
            {
                if (bmpTool == null)
                {
                    bmpTool = new BitmapTool();
                }
                else
                {
                    bmpTool.Reset();
                }
            }

            //开始
            animator.Start();
        }