标题:C#动画处理,gif老是无法正常显示
取消只看楼主
CMYK
Rank: 2
等 级:论坛游民
帖 子:67
专家分:74
注 册:2011-9-19
结帖率:46.15%
已结贴  问题点数:20 回复次数:3 
C#动画处理,gif老是无法正常显示
在做图片软件的时候,遇到gif无法正常显示,这是显示窗体的代码
程序代码:
using System.Drawing;
using System.Windows.Forms;
using System;

namespace WindowsFormsApplication1
{
    class F:Form
    {
        Bitmap bitmap;
        //是否为动画,用于ImageAnimator.Stop判断
        bool IsGif = false;
        private void OnFrameChanged(object o, EventArgs e)
        {
            ImageAnimator.UpdateFrames();
            this.CreateGraphics().DrawImage(this.bitmap, 0, 0);
        }

        //传入图片
        public void ShowImg(Bitmap bt)
        {
            bitmap = bt;
            //窗体设置
            InitializeComponent();

            this.ShowDialog();            
        }

        //绘制
        protected override void OnPaint(PaintEventArgs e)
        {
            if (ImageAnimator.CanAnimate(bitmap))
            {
                //静态图片处理
                ImageAnimator.Animate(bitmap, new EventHandler(this.OnFrameChanged));
                IsGif = true;
            }
            else
            {
                //动态图片处理
                this.CreateGraphics().DrawImage(this.bitmap, 0, 0);
                IsGif = false;
            }
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // F
            // 
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Width = bitmap.Width + 16;
            this.Height = bitmap.Height + 38;
            this.ShowIcon = false;
            this.MaximizeBox = false;

           // this.ClientSize = new System.Drawing.Size(284, 262);
            this.Name = "F";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.F_FormClosing);
            this.ResumeLayout(false);

        }

        //关闭窗体时,释放资源
        private void F_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (IsGif)
                ImageAnimator.StopAnimate(bitmap, new EventHandler(this.OnFrameChanged)); 
            bitmap.Dispose();
        }
    }
}
[local]2[/local]在做图片软件的时候,遇到gif无法正常显示,这是显示窗体的代码
程序代码:
using System.Drawing;
using System.Windows.Forms;
using System;

namespace WindowsFormsApplication1
{
    class F:Form
    {
        Bitmap bitmap;
        //是否为动画,用于ImageAnimator.Stop判断
        bool IsGif = false;
        private void OnFrameChanged(object o, EventArgs e)
        {
            ImageAnimator.UpdateFrames();
            this.CreateGraphics().DrawImage(this.bitmap, 0, 0);
        }

        //传入图片
        public void ShowImg(Bitmap bt)
        {
            bitmap = bt;
            //窗体设置
            InitializeComponent();

            this.ShowDialog();            
        }

        //绘制
        protected override void OnPaint(PaintEventArgs e)
        {
            if (ImageAnimator.CanAnimate(bitmap))
            {
                //静态图片处理
                ImageAnimator.Animate(bitmap, new EventHandler(this.OnFrameChanged));
                IsGif = true;
            }
            else
            {
                //动态图片处理
                this.CreateGraphics().DrawImage(this.bitmap, 0, 0);
                IsGif = false;
            }
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // F
            // 
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Width = bitmap.Width + 16;
            this.Height = bitmap.Height + 38;
            this.ShowIcon = false;
            this.MaximizeBox = false;

           // this.ClientSize = new System.Drawing.Size(284, 262);
            this.Name = "F";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.F_FormClosing);
            this.ResumeLayout(false);

        }

        //关闭窗体时,释放资源
        private void F_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (IsGif)
                ImageAnimator.StopAnimate(bitmap, new EventHandler(this.OnFrameChanged)); 
            bitmap.Dispose();
        }
    }
}
[local]2[/local]
搜索更多相关主题的帖子: 动画 软件 
2012-02-27 10:34
CMYK
Rank: 2
等 级:论坛游民
帖 子:67
专家分:74
注 册:2011-9-19
得分:0 
pic.rar (30.03 KB)
呃,这是程序,大家看看
2012-02-27 10:35
CMYK
Rank: 2
等 级:论坛游民
帖 子:67
专家分:74
注 册:2011-9-19
得分:0 
回复 4楼 xydddaxia
网页打不开,域名ping不通,呃……
2012-02-27 16:43
CMYK
Rank: 2
等 级:论坛游民
帖 子:67
专家分:74
注 册:2011-9-19
得分:0 
回复 3楼 wangnannan
应该可以吧,ImageAnimator类就是专门为动画设计的,我用不大来,版主有这方面的资料没?
2012-02-27 16:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-361698-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.058718 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved