Windows Mobile C#实现GIF图片播放
2013-06-19 10:13
176 查看
网上找个很久关于Mobile6.5播放动态gif的资料,大部分资料都是以下废话。。。
1. 使用WebBrowser控件
2. 使用微软为Wince补充的AnimationControl控件
3. 使用网络上流传的ImageCtrl.dll
4. 仿照Win32代码用C#解码GIF播放
发现1不好,因为还得请求一次链接。
webBrowser.Url =new System.Uri("gif文件");
webBrowser是工具箱中的控件,拖过来就能用。
ImageCtrl.dll 大部分都是C++写的,对于我这种入门级C#菜鸟而言,引用并不好,改写为C#版本后,发现能支持特定gif,自己做的gif有部分不行,不知道啥原因。
最后硬着头皮用微软的AnimationControl控件,代码如下:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace AnimateControl
{
public enum FrameLayouts
{
Horisontal = 0,
Vertical = 1
}
/// <summary>
/// Summary description for AnimateCtl.
/// </summary>
public class AnimateCtl : System.Windows.Forms.Control
{
private Bitmap bitmap;
private int frameCount;
private int frameWidth;
private int frameHeight;
private Graphics graphics;
private int currentFrame = 0;
private int loopCount = 0;
private int loopCounter = 0;
private DateTimePicker dateTimePicker1;
private System.Windows.Forms.Timer fTimer;
public Bitmap Bitmap
{
get { return bitmap; }
set
{
bitmap = value;
}
}
public AnimateCtl()
{
//Cache the Graphics object
graphics = this.CreateGraphics();
//Instanciate the Timer
fTimer = new System.Windows.Forms.Timer();
//Hook up to the Timer's Tick event
fTimer.Tick += new System.EventHandler(this.timer1_Tick);
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if (loopCount == -1) //loop continuosly
{
this.DrawFrame();
}
else
{
if (loopCount == loopCounter) //stop the animation
fTimer.Enabled = false;
else
this.DrawFrame();
}
}
public void StartAnimation(int frWidth, int DelayInterval, int LoopCount)
{
frameWidth = frWidth;
//How many times to loop
loopCount = LoopCount;
//Reset loop counter
loopCounter = 0;
//Calculate the frameCount
frameCount = bitmap.Width / frameWidth;
frameHeight = bitmap.Height;
//Resize the control
this.Size = new Size(frameWidth, frameHeight);
//Assign delay interval to the timer
fTimer.Interval = DelayInterval;
//Start the timer
fTimer.Enabled = true;
}
public void StopAnimation()
{
fTimer.Enabled = false;
}
private void DrawFrame()
{
if (currentFrame < frameCount - 1)
{
currentFrame++;
}
else
{
//increment the loopCounter
loopCounter++;
currentFrame = 0;
}
Draw(currentFrame);
}
private void Draw(int iframe)
{
//Calculate the left location of the drawing frame
int XLocation = iframe * frameWidth;
Rectangle rect = new Rectangle(XLocation, 0, frameWidth, frameHeight);
//Draw image
graphics.DrawImage(bitmap, 0, 0, rect, GraphicsUnit.Pixel);
}
private void InitializeComponent()
{
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(0, 0);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(200, 22);
this.dateTimePicker1.TabIndex = 0;
this.ResumeLayout(false);
}
}
}
说白了,就是把gif动态图做成静态的一帧一帧的,然后去调用
animCtl = new AnimateCtl();
//Assign the image file
animCtl.Bitmap = BarCodeDemo.Properties.Resources.dengdai2;
//Set the location
animCtl.Location = new Point(0, 0);
//Add to control to the Form
关于gif变成一帧一帧的工具,比如Gif分离器
this.panel1.Controls.Add(animCtl);
1. 使用WebBrowser控件
2. 使用微软为Wince补充的AnimationControl控件
3. 使用网络上流传的ImageCtrl.dll
4. 仿照Win32代码用C#解码GIF播放
发现1不好,因为还得请求一次链接。
webBrowser.Url =new System.Uri("gif文件");
webBrowser是工具箱中的控件,拖过来就能用。
ImageCtrl.dll 大部分都是C++写的,对于我这种入门级C#菜鸟而言,引用并不好,改写为C#版本后,发现能支持特定gif,自己做的gif有部分不行,不知道啥原因。
最后硬着头皮用微软的AnimationControl控件,代码如下:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;
namespace AnimateControl
{
public enum FrameLayouts
{
Horisontal = 0,
Vertical = 1
}
/// <summary>
/// Summary description for AnimateCtl.
/// </summary>
public class AnimateCtl : System.Windows.Forms.Control
{
private Bitmap bitmap;
private int frameCount;
private int frameWidth;
private int frameHeight;
private Graphics graphics;
private int currentFrame = 0;
private int loopCount = 0;
private int loopCounter = 0;
private DateTimePicker dateTimePicker1;
private System.Windows.Forms.Timer fTimer;
public Bitmap Bitmap
{
get { return bitmap; }
set
{
bitmap = value;
}
}
public AnimateCtl()
{
//Cache the Graphics object
graphics = this.CreateGraphics();
//Instanciate the Timer
fTimer = new System.Windows.Forms.Timer();
//Hook up to the Timer's Tick event
fTimer.Tick += new System.EventHandler(this.timer1_Tick);
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if (loopCount == -1) //loop continuosly
{
this.DrawFrame();
}
else
{
if (loopCount == loopCounter) //stop the animation
fTimer.Enabled = false;
else
this.DrawFrame();
}
}
public void StartAnimation(int frWidth, int DelayInterval, int LoopCount)
{
frameWidth = frWidth;
//How many times to loop
loopCount = LoopCount;
//Reset loop counter
loopCounter = 0;
//Calculate the frameCount
frameCount = bitmap.Width / frameWidth;
frameHeight = bitmap.Height;
//Resize the control
this.Size = new Size(frameWidth, frameHeight);
//Assign delay interval to the timer
fTimer.Interval = DelayInterval;
//Start the timer
fTimer.Enabled = true;
}
public void StopAnimation()
{
fTimer.Enabled = false;
}
private void DrawFrame()
{
if (currentFrame < frameCount - 1)
{
currentFrame++;
}
else
{
//increment the loopCounter
loopCounter++;
currentFrame = 0;
}
Draw(currentFrame);
}
private void Draw(int iframe)
{
//Calculate the left location of the drawing frame
int XLocation = iframe * frameWidth;
Rectangle rect = new Rectangle(XLocation, 0, frameWidth, frameHeight);
//Draw image
graphics.DrawImage(bitmap, 0, 0, rect, GraphicsUnit.Pixel);
}
private void InitializeComponent()
{
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.SuspendLayout();
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(0, 0);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(200, 22);
this.dateTimePicker1.TabIndex = 0;
this.ResumeLayout(false);
}
}
}
说白了,就是把gif动态图做成静态的一帧一帧的,然后去调用
animCtl = new AnimateCtl();
//Assign the image file
animCtl.Bitmap = BarCodeDemo.Properties.Resources.dengdai2;
//Set the location
animCtl.Location = new Point(0, 0);
//Add to control to the Form
关于gif变成一帧一帧的工具,比如Gif分离器
this.panel1.Controls.Add(animCtl);
相关文章推荐
- [Windows Mobile] C#实现GIF图片播放
- C#实现GIF图片播放
- C# windows mobile中实现控件的动态绘制与动态删除
- Android 实现播放本地GIF图片
- c#实现图片gif去水印
- c# 怎样实现用几张图片制作 gif?怎样对图片像素值进行修改?上代码
- Coretext实现图文混排及Gif图片播放
- 实现android gif图片动画播放功能
- CSS或JS实现gif动态图片的停止与播放
- c#实现图片gif去水印
- .net c# gif动画如何添加图片水印实现思路及代码
- C# WinForm 添加等待界面 利用Gif图片实现
- Android轻松实现播放Gif图片
- Android实现GIF图片解码与播放
- iPhone上用OpenGL实现gif图片动画播放的代码
- C#实现GIF图片反转
- .net c# gif动画如何添加图片水印实现思路及代码学习
- C#实现拆分、合并GIF图片
- C#调用WindowsMediaPlayer控件实现音乐播放(一)
- [c#][Windows 10 | Windows 10 mobile | Windows Phone] HttpClient 实现form-data POST上传请求