View previous topic :: View next topic |
Author |
Message |
tyro
Joined: 04 Dec 2004 Posts: 13
|
Posted: Fri Aug 28, 2009 6:22 pm Post subject: How do you Animate a GIF in a PictureBox? |
|
|
I have an animated GIF I would like to display on a form and attempted to do so using a PictureBox. The image displays but is not animated. What is the proper way to do this? A pointer to the documentation or a short example will suffice.
Thank you,
Andrew |
|
Back to top |
|
|
tyro
Joined: 04 Dec 2004 Posts: 13
|
Posted: Tue Sep 15, 2009 5:23 am Post subject: |
|
|
I searched far and wide and the closest thing I can find that seems to be able to get the job done is the System.Drawing.ImageAnimator class defined in the .NET framework.
It is a class that inherits form System.Object and has the following C++ interface according to the .NET Framework Development Center.
public ref class ImageAnimator sealed
{
public: static void Animate(Image^ image, EventHandler^ onFrameChangedHandler);
public: static bool CanAnimate(Image^ image);
public: static void StopAnimate(Image^ image, EventHandler^ onFrameChangedHandler);
public: static void UpdateFrames();
public: static void UpdateFrames();
}
I'm not at all savy on porting this interface to D and am wondering if someone can help me accomplish this.
Thanks,
Andrew |
|
Back to top |
|
|
tyro
Joined: 04 Dec 2004 Posts: 13
|
Posted: Tue Sep 15, 2009 1:37 pm Post subject: |
|
|
Borrowing from the examples on MSDN here is my attempt at this:
extern(Windows)
{
class ImageAnimator: dfl.form.Form
{
void Animate(Image image, EventHandler onFrameChangedHandler);
bool CanAnimate(Image image);
void StopAnimate(Image image, EventHandler onFrameChangedHandler);
void UpdateFrames();
void UpdateFrames(Image image);
void Invalidate();
}
}
class MyForm: ImageAnimator
{
void onFrameChanged(Object o, EventArgs ea)
{
//Force a call to the Paint event handler.
Invalidate();
}
override void onPaint(PaintEventArgs ea)
{
UpdateFrames();
}
this()
{
picAnimated.image = new Picture(`image\43_ani.gif`);
Animate(picAnimated.image, EventHandler(this, &onFrameChanged));
}
}
I keep getting the following error messages and am not sure how to resolve them. I am sure I did a number of things incorrectly so any assistance would be really appreciated:
D:\code>dfl -gui -version=DFL_DMD2020 -ofhayato.exe -release myform2
Error checking versions; use switch -ver for details
Compiling in release mode; safety checks removed
C:\Users\Andrew\dmd2\windows\bin\dmd.exe -version=DFL_DMD2020 -ofhayato.exe -rel
ease myform2 -version=DFL_EXE -IC:\Users\Andrew\dmd2\windows\import -L/exet:nt/s
u:windows:4.0 C:\Users\Andrew\dmd2\windows\lib\dfl.lib
myform2.d(249): Error: function dfl.event.Event!(Object,EventArgs).Event.opCall
(Object v1, EventArgs v2) is not callable using argument types (MyForm,void dele
gate(Object, EventArgs))
myform2.d(249): Error: this for opCall needs to be type Event not type myform2.M
yForm
myform2.d(249): Error: class myform2.MyForm member opCall is not accessible
myform2.d(249): Error: cannot implicitly convert expression (&this.onFrameChange
d) of type void delegate(Object, EventArgs) to dfl.event.EventArgs
myform2.d(249): Error: function myform2.ImageAnimator.Animate (Image image, Even
t!(Object,EventArgs) onFrameChangedHandler) is not callable using argument types
(Image,void)
myform2.d(249): Error: function myform2.ImageAnimator.Animate (Image image, Even
t!(Object,EventArgs) onFrameChangedHandler) is not callable using argument types
(Image,void)
myform2.d(249): Error: cannot implicitly convert expression (this.opCall(cast(Ob
ject)this,cast(EventArgs)(&this.onFrameChanged))) of type void to Event!(Object,
EventArgs)
Returned status code 1 |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Tue Sep 15, 2009 7:44 pm Post subject: |
|
|
Sounds like you have a DFL installation or version issue, type dfl -ver and see what it says. |
|
Back to top |
|
|
tyro
Joined: 04 Dec 2004 Posts: 13
|
Posted: Wed Sep 16, 2009 4:16 am Post subject: |
|
|
Interesting enough dfl -ver produces an error:
D:\code>dfl -ver
Using Phobos library
std.file.FileException: C:\Users\Andrew\dmd2\windows\packages\dfl\readme.txt: Th
e system cannot find the file specified.
I haven't had a packages folder for the longest time. Only thing I have on the system is the dfl folder which I placed in src.phobos and windows.import which contains a symbolic link to src.phobos to reduce duplication. I had been using version 0.9.8 with simple changes I've been making to keep current with DMD v2.*. I compiled and dflexe back when I first installed 0.9.8 (November last year) and haven't touched it since. I had to stop using the "dfl" I was maintaining when I started using DMD v2.32 and ran into the errors referred to in "Error: mixin is not defined (dmd v2.032)".
The version of the library I'm currently using was downloaded from a link in this post http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=96000. Thanks to Robert Jacques, this corrected the aforementioned errors and seems to work correctly producing no errors until I began attempting to incorporate the ImageAnimator Class. |
|
Back to top |
|
|
|