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
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;
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)}
}
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.
I'm using WP Toolkit to do the transitions between my app pages, it works fine , but I get this strange delay in between transitions while navigating from one page to another, it just shows a blank screen which obviously doesn't look good, without any transition it opens the page straight away without any delay or blank screen. This has taken almost 2 days of my time and I don't know what's wrong, I'd appreciate it if someone can help me with it or suggest another page transition library .
(I tried WP7Contrib transitions but I have the same problem with that, not sure if its my app or the libraries)
In fact the background between transitions is black and to avoid that kind of behavior I solved the issue by setting the background in the App.Xaml.cs
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new TransitionFrame();
var brush = new ImageBrush
{
ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("Images/Background.jpg", UriKind.Relative)),
Opacity = 0.8d
};
RootFrame.Background = brush;
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
With that all my pages have my background and the black background is no longer displayed during the transition.
I would suggest you to create your own slide transitions between pages. Its quite simple actually. Create a storyboard and play them at onNavigatingFrom and onNavigatedTo functions in both the page you are navigating from and page you are going into respectively. It just gives me what and how i wanted in my applications. Removing additional references makes your code more optimized.
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/.