Display an Animated GIF in a Metro App - c#

Is there a control to show an animated gif in a Windows Store (Metro) app in Windows 8? I am using C# and XAML with databinding.

The Image control doesn't support animated GIFs. You will need to extract the frames and animate them on your own timer.
You should take a look at this link which might help you regarding your question:
http://advertboy.wordpress.com/2012/05/08/animated-gifs-in-xamlc/

You cannot display an animated gif in a grid. However, you can display an animated gift in the webview controller.

Just for a note: you can use the BitmapDecoder class to read the GIF frames, create a storyboard an animated them.
I've got an example of an Windows 8 user control on my blog: http://www.henrikbrinch.dk/Blog/2013/02/21/Windows-8---GIF-animations--the-RIGHT-way

I managed to display gif's in my windows 8 metro app simply by converting the gifs to jpegs and then running an infinite loop.
The code is as follows :
public async void UpdateImage()
{
await Task.Delay(300);
var frame = this.Frame.CurrentSourcePageType.Name;
if (frame != ("CURRENTFRAME")) return;
if (count <= 4)
{
var img = (BitmapImage) Resources["bitmap" + count];
imgTap.Source = img;
UpdateLayout();
count++;
UpdateImage();
}
else
{
count = 1;
UpdateImage();
}
}
So basically I'm saving the converted jpegs in my page.resources and then naming them as bitmap1,bitmap2 .. etc .
I m checking whether the current frame is the frame which has to display the gif or else the gif code would run in the background for the entire time which is a waste of memory and CPU.
Just call this method on any of the Loaded method and it should run fine.

This is probably overkill, but you could try using a WebView to display the GIF. The WebView control introduces its own set of headaches, however, so unless you're willing to deal with said headaches, I would recommend avoiding it unless you absolutely have to use it.

If I am right then Silverlight doesn't support GIF and Metro Apps are based on Silverlight platform. Hence dont contain support for GIF images natively. You can however use 3rd party controls like http://www.componentone.com/SuperProducts/ImageSilverlight/.

Related

How to disable a looping for gif image and save it in c#

In my application, there is an image uploading and if a user wants to upload gif image. I need to disable looping in an image and save it, in the result gif image of a user must be played once and stop after that. Maybe I need to delete pointer from the last frame of gif image? Any ideas?
You need to add or change the Netscape Application extension block. In this block there are 2 bytes to control the looping, see details in the following answer:
https://stackoverflow.com/a/28486261/3936440
I couldn't find a proper package for GIF manipulation but i think you can use BumpKit as an inspiration as mentioned here
https://stackoverflow.com/a/32810041/3936440
or
https://github.com/DataDink/Bumpkit/blob/master/BumpKit/BumpKit/GifEncoder.cs
I found an answer, thank you all who tried to helped me.
The gif image has a set of properties which you can get if you know the specific address of a byte of each property.
For example, 20737 is looping property.
if this property set to 0 gif image will have infinite looping, but if set this property great than 0 gif image will be repeated infinitely. The example I placed here.
var image = System.Drawing.Image.FromFile(path)
var IsLooped = BitConverter.ToInt16(image.GetPropertyItem(20737).Value, 0) != 1;

Animate images on VB C#

I am looking to animate a set of images and perform different actions dependent on which images are showing.
There are 13 images (ball1, ball2, ..., ball13), once the series reaches 'ball6' I need to a graphic to be created from the centre of the image. After that has happened it will need to pause/hold/wait for maybe 2 seconds and then follow onto 'ball7' (this is why a .gif hasn't been used). The animation needs to continue until the end (ball13) then create a different graphic and finally pause again for 2 seconds before restart the cycle...
I am poor with graphics and I am looking to learn this field so as much information as possible is appreciated.
Edits
Sorry, using WinForms at present, willing to convert for simplicity as this is start of newest project.
I loaded the application again, re-imported images using WinForms as that supports .gif files. You can simply switch between the .Image file for each .gif at any point with one line of code; using a bool if it fits nicely which it did for me.
This isn't correct code, just draft.
bool picswitch = false;
_For Loop here_
{
if (picswitch = false)
{pictureBox1.image (*.png)}
else if (picswitch = true)
{pictureBox1.image (*.png)}
}

Need to select a frame in gif

I need to restart a gif image so it will start from the first frame.
I have little experience with gif images in C#. I work on a C# windows form application. My gif image is in a picturebox. I need to restart it each time a person for example presses a button.
I have tried doing:
pictureBox1.Image.SelectActiveFrame(new FrameDimension(pictureBox1.Image.FrameDimensionsList[0]), 0)
but it didnt show any change.
I also tried Image animator also no luck. I really need help it is for my final project in high school engineering.
I found that Image.SelectActiveFrame() doesn't seem to work because how it works is not what you thought. It just set the initial frame if there is some control reading its frame, the first frame read is the active frame. So after SelectActiveFrame() you have to re-assign the Image property of your pictureBox to that new Image, like this:
private void RestartToFrameIndex(int index){
pictureBox.Image.SelectActiveFrame(new FrameDimension(pictureBox.Image.FrameDimensionsList[0]), index);
pictureBox.Image = pictureBox.Image;
}
//If you want to restart to the first frame, just call the method above like this:
RestartToFrameIndex(0);
That's the general solution I've just found :) hope it helps others...
I tried this solution and It's working fine :
Image animated = pictureBox1.Image;
pictureBox1.Image = animated;
this way , you reset pictureBox1.Image so the animated GIF starts from beginning.

Animations in Windows 8 [duplicate]

Is there a control to show an animated gif in a Windows Store (Metro) app in Windows 8? I am using C# and XAML with databinding.
The Image control doesn't support animated GIFs. You will need to extract the frames and animate them on your own timer.
You should take a look at this link which might help you regarding your question:
http://advertboy.wordpress.com/2012/05/08/animated-gifs-in-xamlc/
You cannot display an animated gif in a grid. However, you can display an animated gift in the webview controller.
Just for a note: you can use the BitmapDecoder class to read the GIF frames, create a storyboard an animated them.
I've got an example of an Windows 8 user control on my blog: http://www.henrikbrinch.dk/Blog/2013/02/21/Windows-8---GIF-animations--the-RIGHT-way
I managed to display gif's in my windows 8 metro app simply by converting the gifs to jpegs and then running an infinite loop.
The code is as follows :
public async void UpdateImage()
{
await Task.Delay(300);
var frame = this.Frame.CurrentSourcePageType.Name;
if (frame != ("CURRENTFRAME")) return;
if (count <= 4)
{
var img = (BitmapImage) Resources["bitmap" + count];
imgTap.Source = img;
UpdateLayout();
count++;
UpdateImage();
}
else
{
count = 1;
UpdateImage();
}
}
So basically I'm saving the converted jpegs in my page.resources and then naming them as bitmap1,bitmap2 .. etc .
I m checking whether the current frame is the frame which has to display the gif or else the gif code would run in the background for the entire time which is a waste of memory and CPU.
Just call this method on any of the Loaded method and it should run fine.
This is probably overkill, but you could try using a WebView to display the GIF. The WebView control introduces its own set of headaches, however, so unless you're willing to deal with said headaches, I would recommend avoiding it unless you absolutely have to use it.
If I am right then Silverlight doesn't support GIF and Metro Apps are based on Silverlight platform. Hence dont contain support for GIF images natively. You can however use 3rd party controls like http://www.componentone.com/SuperProducts/ImageSilverlight/.

c# How can I make my gif animation loop in a picturebox

I have imported an animated GIF as a resource into a picturebox - unfortunitly it only plays to the end frame and never repeats. Id there something I could do to make it loop continiously. The gif is for my "please wait busy box"
Brad
Animated GIFs have a few different settings. Usually, embedded in the file is some data that tells the renderer how the image should be displayed.
This data says how fast the image is animated, if it should loop infinitely, or how many times it should repeat.
There are several programs available that you can use to edit an animated GIF and change the looping settings.
First, I'd open your GIF in some app to preview it to see if it loops before trying to alter the image.
You can use the System.Drawing.ImageAnimator class helper. You have the Animate, UpdateFrames, and StopAnimate methods to control the loop.

Categories

Resources