PDA

View Full Version : یه مثال برای شبیه سازی فایل gif



combo_ci
دوشنبه 12 آذر 1386, 16:39 عصر
شاید شما هم براتون پیش اومده که بخواین یه فایل gif رو تو برنامه نشون بدین...توی این مثال شما 2 تا عکس رو توی Resources برنامه تعریف میکنین ...خودش به شورت gif براتون نمایش میده...

فقط یه کاری نتونستم بکنم....یکی اینکه وقتی نمایش عکس دوم تموم میشه و میخواد برگرده به حالت اول یک delay مثلا 1 ثانیه ای ایجاد کنم که نمایش فایل gif قشنگ تر بشه
دوم هم اینکه عکس اول من یه فایل با background سفید هست اما تو برنامه سیاه نشون میده !!!!

http://virga.persiangig.ir/Programming/C%20Sharp/gif.rar

ARA
سه شنبه 13 آذر 1386, 09:43 صبح
من از این استفاه میکنم
این روش خوبیه از MSDN
فقط خواستی نرم تر نشون بده این رو هم تو initial فرم بگذار


this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer
| ControlStyles.UserPaint , true);





using System;
using System.Drawing;
using System.Windows.Forms;
publicclass animateImage : Form
{

//Create a Bitmpap Object.
Bitmap animatedImage = new Bitmap("SampleAnimation.gif");
bool currentlyAnimating = false;

//This method begins the animation.
publicvoid AnimateImage()
{
if (!currentlyAnimating)
{

//Begin the animation only once.
ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
currentlyAnimating = true;
}
}
privatevoid OnFrameChanged(object o, EventArgs e)
{

//Force a call to the Paint event handler.
this.Invalidate();
}
protectedoverridevoid OnPaint(PaintEventArgs e)
{

//Begin the animation.
AnimateImage();

//Get the next frame ready for rendering.
ImageAnimator.UpdateFrames();

//Draw the next frame in the animation.
e.Graphics.DrawImage(this.animatedImage, new Point(0, 0));
}
publicstaticvoid Main()
{
Application.Run(new animateImage());
}
}