【发布时间】:2016-03-17 09:33:05
【问题描述】:
我有一个winforms 应用程序,上面有一个 gif,可以让用户了解停止进程。
问题在于它的播放速度比在其他应用程序(chrome、Internet Explorer)上看起来要慢得多。
我在PictureBox 和Label 上尝试过gif,但结果速度是一样的。然后经过一点研究,我遇到了this 问题和传奇@Hans Passant 的答案,但不幸的是,应用他建议的样板代码并没有任何区别。
下面是简单的重现代码:
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent();
timeBeginPeriod(timerAccuracy);
}
protected override void OnFormClosed ( FormClosedEventArgs e )
{
timeEndPeriod(timerAccuracy);
base.OnFormClosed(e);
}
// Pinvoke:
private const int timerAccuracy = 10;
[System.Runtime.InteropServices.DllImport("winmm.dll")]
private static extern int timeBeginPeriod ( int msec );
[System.Runtime.InteropServices.DllImport("winmm.dll")]
public static extern int timeEndPeriod ( int msec );
}
如果需要,还有设计器代码:
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose ( bool disposing )
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent ()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 9);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(166, 119);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Image = ((System.Drawing.Image)(resources.GetObject("label1.Image")));
this.label1.Location = new System.Drawing.Point(180, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(158, 119);
this.label1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(346, 134);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
}
两个 gif 以相同的速度播放,但低于实际 gif。在应用此代码时,我还有什么需要注意的吗?
【问题讨论】:
-
你为什么将其设置为 0 精度?
-
这个 gif 在我看来就像一个应用程序资源。您不能使用一些 gif 编辑器简单地修改原始 gif 吗?只需让它变慢,例如通过删除每一秒帧并延长剩下的每一帧的持续时间。重复直到结果令人满意。
-
我尝试了不同的精度值,0 - 10 - 1000 :) 但是没有任何区别。现在我也在问题中将其设置回 10。
-
@Sinatr,我已通过
properties->image->import添加了 gif。无论如何,我认为拥有 gif 的真正速度效果并不需要如此痛苦。 -
也许操作系统确实很重要。你编译它的确切 .net 框架是什么,你在哪个操作系统上运行它?
标签: c# winforms time animated-gif