回答
把一个图片框放在一个表格上,然后用一个Gif扩展名指定一个图片文件。或者:
编程方式动画GIF图像加载架与代码中的图片框,这里的的Gif类:
VB.NET
Public Class GifImage
Private gifImage As Image
Private dimension As FrameDimension
Private frameCount As Integer
Private currentFrame As Integer = -1
Private reverse As Boolean
Private [step] As Integer = 1
Public Sub New(path As String)
gifImage = Image.FromFile(path)
'initialize
dimension = New FrameDimension(gifImage.FrameDimensionsList(0))
'gets the GUID
'total frames in the animation
frameCount = gifImage.GetFrameCount(dimension)
End Sub
Public Property ReverseAtEnd() As Boolean
'whether the gif should play backwards when it reaches the end
Get
Return reverse
End Get
Set
reverse = value
End Set
End Property
Public Function GetNextFrame() As Image
currentFrame += [step]
'if the animation reaches a boundary...
If currentFrame >= frameCount OrElse currentFrame < 1 Then
If reverse Then
[step] *= -1
'...reverse the count
'apply it
currentFrame += [step]
Else
currentFrame = 0
'...or start over
End If
End If
Return GetFrame(currentFrame)
End Function
Public Function GetFrame(index As Integer) As Image
gifImage.SelectActiveFrame(dimension, index)
'find the frame
Return DirectCast(gifImage.Clone(), Image)
'return a copy of it
End Function
End Class
C#
public class GifImage
{
private Image gifImage;
private FrameDimension dimension;
private int frameCount;
private int currentFrame = -1;
private bool reverse;
private int step = 1;
public GifImage(string path)
{
gifImage = Image.FromFile(path);
//initialize
dimension = new FrameDimension(gifImage.FrameDimensionsList[0]);
//gets the GUID
//total frames in the animation
frameCount = gifImage.GetFrameCount(dimension);
}
public bool ReverseAtEnd {
//whether the gif should play backwards when it reaches the end
get { return reverse; }
set { reverse = value; }
}
public Image GetNextFrame()
{
currentFrame += step;
//if the animation reaches a boundary...
if (currentFrame >= frameCount || currentFrame < 1) {
if (reverse) {
step *= -1;
//...reverse the count
//apply it
currentFrame += step;
}
else {
currentFrame = 0;
//...or start over
}
}
return GetFrame(currentFrame);
}
public Image GetFrame(int index)
{
gifImage.SelectActiveFrame(dimension, index);
//find the frame
return (Image)gifImage.Clone();
//return a copy of it
}
}
C#的使用:
打开一个WinForm项目在PictureBox,一个定时器和一个按钮拖放,与上文所示的GifImage.cs
类。
public partial class Form1 : Form
{
private GifImage gifImage = null;
private string filePath = @"C:\Users\Jeremy\Desktop\ExampleAnimation.gif";
public Form1()
{
InitializeComponent();
//a) Normal way
//pictureBox1.Image = Image.FromFile(filePath);
//b) We control the animation
gifImage = new GifImage(filePath);
gifImage.ReverseAtEnd = false; //dont reverse at end
}
private void button1_Click(object sender, EventArgs e)
{
//Start the time/animation
timer1.Enabled = true;
}
//The event that is animating the Frames
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = gifImage.GetNextFrame();
}
}
你能告诉我如何使用代码片段吗?我的意思是如何在使用该类的图片框中加载图片,我无法找到使用该代码的方式,但很有趣... – ElektroStudios
最新问题? –
例如:Dim asdasd As New GifImage =“C:\ image。gif“ PictureBox1.Image = GifImage(”C:\ image.gif“)问题是我不知道如何使用它,抱歉,我是一个小新手,如果你能解释我请...我想要手动加载 – ElektroStudios
开发上@ JeremyThompson的答案,我想添加一段代码来向您展示如何实现第一种方法,因为它是简单了很多,而且不需要你手动动画该gif,看到PictureBox
有一个内置的功能来处理这种情况。 只需添加一个PictureBox
到表单,并在窗体构造函数中指定图像路径PictureBox.ImageLocation
C#
public PictureForm()
{
InitializeComponent();
pictureBoxGif.ImageLocation = "C:\\throbber.gif";
}
VB.Net
Public Sub New()
InitializeComponent()
pictureBoxGif.ImageLocation = "C:\throbber.gif"
End Sub
在我oppinion这是一个非常更简单的解决方案,特别适用于.NET新手。
+1为体育道德, **如果在VB6中只有这些东西很简单**。“.Net'的喜悦,真的,随着我继续增长,我注意到托管框架的好处多多! –
+1与您的解决方案相关,简单和完美请注意,禁用图片框(或表单)将阻止gif的动画! – Marco
我已经玩过这个和动画剧,只要你不在同一个线程上执行另一个长时间运行的操作。当你执行另一个长时间运行的操作时,你会想在另一个线程中执行它。
执行此操作的最简单方法是使用可从工具箱拖到表单上的BackgroundWorker组件。然后,您将长时间运行的操作代码放入BackgroundWorker的DoWork()事件中。最后一步是通过调用BackgroundWorker实例的RunWorkerAsync()方法来调用您的代码。
- 1. 未能在Android应用程序中显示动画GIF图像
- 2. 如何在Android应用程序中显示动画GIF图像?
- 3. 如何在Windows Phone 8.1(RT)应用程序中显示动画GIF?
- 4. 可以在Glass时间轴上显示动画GIF吗?
- 5. tkinter gif不动,可以tkinter显示动画吗?
- 6. 显示gif动画
- 7. 显示gif动画
- 8. 显示动画GIF
- 9. 显示gif动画
- 10. gif动画没有动画,同时使可见= true的PictureBox
- 11. 您可以将GIF和/或动画GIF加入单个动画GIF吗?
- 12. springframework.net可以在Windows移动应用程序中使用吗?
- 13. 防止WinForms PictureBox动画GIF在处理过程中暂停?
- 14. 在gridview中显示GIF动画
- 15. 在QLabel中显示.gif动画
- 16. WinRT - 在控件中显示动画GIF
- 17. 在Android中显示动画GIF
- 18. 计时动画gif显示
- 19. JLabel不显示.gif动画
- 20. 我们可以动画显示吗?
- 21. 显示动画GIF后显示信息
- 22. 我可以在iPhone上使用UIImageView叠加动画GIF吗?
- 23. 我可以在ActionScript中使GIF动画帧更快播放吗?
- 24. Xcode iPhone SDK - 在应用程序上显示gif图像启动
- 25. python tkinter使用PIL显示动画GIF
- 26. Windows桌面应用程序可以在Windows Phone上使用吗?
- 27. 在Picturebox中使用动画
- 28. 在应用程序中反编译动画GIF文件
- 29. 在iPad应用程序中加载动画gif
- 30. GIF图像没有在反应本机中显示动画
为动画图像,你可以使用这个控制器。 http://www.codeproject.com/Tips/1004624/Gif-viewer-Snipper-control – xwpedram