LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Animated Gif in PictureBox DotNet

Solved!
Go to solution

Okay so I'm unsure why this isn't working.  I have an animated gif that I want to load from a file on disk.  I do not want to embed the gif on the front panel I want it loaded from a file at runtime.

 

Using the .Net PictureBox I can load an image from a file, but if it is a gif it is not animated.  I've tried several gifs and all of them just show the first static frame.  Is there something I'm missing to allow a gif to be loaded in a PictureBox?  Attached is an example gif and code for loading an image taken from here. Thanks.

 

 

Download All
0 Kudos
Message 1 of 7
(6,620 Views)

I am not sure why it is not either. I get the same result. I found this link but the reasons why it does not work (LV Picture not .Net) does not make sense, since you are using the .Net control.  http://digital.ni.com/public.nsf/allkb/8D5E7940947C60B486256E92007F46D0

 

I also found this thread on using it in .Net and way down the page is an interesting topic on why it does not work during long operations using the same thread and I wonder if this couldbe that LV forces this to run in UI thread and thats what is causing the hang up.

 

http://stackoverflow.com/questions/13485477/can-a-picturebox-show-animated-gif-in-windows-applicatio...

"

I've played around with this and the animation plays provided that you don't perform another long running operation on the same thread. The moment you perform another long running operation, you'd want to do it in another thread.

The simplest way to do this, is to use the BackgroundWorker component that you can drag onto the form from your toolbox. You'd then put your long running operation code in the DoWork() event of the BackgroundWorker. The final step would be to invoke your code by calling the RunWorkerAsync() method of the BackgroundWorker instance."

 

 




Joe.
"NOTHING IS EVER EASY"
Message 2 of 7
(6,576 Views)

You might try an image animator....maybe. 

https://msdn.microsoft.com/en-us/library/system.drawing.imageanimator.animate(v=vs.110).aspx

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 7
(6,564 Views)

@aputman wrote:

You might try an image animator....maybe. 

https://msdn.microsoft.com/en-us/library/system.drawing.imageanimator.animate(v=vs.110).aspx


Yup thanks I was looking into that when I saw your reply.  There is some example code at the bottom and trying to recreate it I run into a few issues I've never seen before.  Attached is my failed attempt to figure it out.  Basically I understand I need to use the Animate method giving the image and a type of call back that gets ran when it advances to the next image, so I can invalidate the image, and load the next one.  But what I haven't figured out is how to get the OnPaint, or OnFrameChanged callback.  And even if I did I couldn't figure out how to invalidate the image.  Any help is appreciated.

0 Kudos
Message 4 of 7
(6,560 Views)

That's why I said "....maybe."  I tried figuring it out before posting that and had the same issues.  Also not sure how to get the image out of the animator to add it to the PictureBox.

 

Can't open your failed attempt.  Still on 2012.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 7
(6,549 Views)
Solution
Accepted by topic author Hooovahh

I didn't look at any of the code in this thread, but what's wrong with using the .NET container to embed a web browser and tell it to navigate to the file? A quick attempt here shows that it displays the animated GIF just fine.


___________________
Try to take over the world!
Message 6 of 7
(6,529 Views)

Wow little embarissed I didn't think of this...but now that I tried it it also doesn't work, which is quite odd.  My gif in IE doesn't animate (and therefore the ActiveX broswer doesn't), but opening it in chrome does work...I'll have to look into it a bit.

 

Edit:  Looked like it was an IE setting.

0 Kudos
Message 7 of 7
(6,512 Views)