none
How to play .gif files in Windows Phone 7

    Question

  • Hello All!

    In my application I want to play .gif files in my application. I search for it on net and I came to know that it require ImageTools.dll file. But I didn't get this file. Where it is stored? How can I play a gif in my app? Which controls it require?

    Any body any suggestion or any helpful link you can provide?
    Thanks!!

    Tuesday, January 17, 2012 11:03 AM

Answers

  • Umm... it works fine for me.

    2. Open and build the VS solution: /src/ImageTools/ImageTools.Phone.sln
    3. Open the demo project: /src/ImageTools/Demos/ImageTools.Demos.Phone/ImageTools.Demos.Phone.csproj
    4. Expand the References folder. Delete the references that are marked as missing. Add as new references the dlls in the folder /bin/Phone
    5. Build the project and verify that you can run it.
    6. To the Images project folder, add the nine Smiley*.gif images from the folder /src/ImageTools/Demos/ImageTools.Demos/Images
    7. Add this PivotItem to MainPage.xaml
            <controls:PivotItem Header="gif"
                <StackPanel Background="Gray"
                    <it:AnimatedImage x:Name="SmileyCool" Height="20" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyCursing" Height="24" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyDrool" Height="25" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyGrins" Height="18" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyHuh" Height="20" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyJedi" Height="40" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyLol" Height="20" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyLove" Height="18" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyWink" Height="20" Margin="10"/> 
                </StackPanel> 
            </controls:PivotItem> 
    8. Add initialization code to the constructor in MainPage.xaml.cs
            public MainPage() 
            { 
                InitializeComponent(); 
     
                ImageTools.IO.Decoders.AddDecoder<ImageTools.IO.Gif.GifDecoder>(); 
     
                SmileyCool.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyCool.gif", UriKind.Relative) }; 
                SmileyCursing.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyCursing.gif", UriKind.Relative) }; 
                SmileyDrool.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyDrool.gif", UriKind.Relative) }; 
                SmileyGrins.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyGrins.gif", UriKind.Relative) }; 
                SmileyHuh.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyHuh.gif", UriKind.Relative) }; 
                SmileyJedi.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyJedi.gif", UriKind.Relative) }; 
                SmileyLol.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyLol.gif", UriKind.Relative) }; 
                SmileyLove.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyLove.gif", UriKind.Relative) }; 
                SmileyWink.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyWink.gif", UriKind.Relative) }; 
     
                SmileyCool.Start(); 
                SmileyCursing.Start(); 
                SmileyDrool.Start(); 
                SmileyGrins.Start(); 
                SmileyHuh.Start(); 
                SmileyJedi.Start(); 
                SmileyLol.Start(); 
                SmileyLove.Start(); 
                SmileyWink.Start(); 
            } 
    9. Build and run the app.


    Richard Woo
    Friday, February 17, 2012 8:56 AM

All replies

  • A five-second web search for "windows phone gif image" gave many links to solutions for displaying GIF images.  The very first link led to .NET Image Tools on codeplex.
    Tuesday, January 17, 2012 11:09 AM
  • Thanks for reply!
    I already went through this link. But my problem is I am not getting this dll file. I downloaded it from net but where it should keep I don't know? I am looking for this.

    Thanks!
    Tuesday, January 17, 2012 12:09 PM
  • Click the big green Download button on the right of the page.  This download contains ImageTools.dll and all related DLLs.  Also in the download is documentation, along with the How-To articles linked on that site.
    Tuesday, January 17, 2012 1:49 PM
  • If the imagetools library wont fit your needs, you can also use the WebBrowser control. Here is a link to start width: http://social.msdn.microsoft.com/Forums/en-US/wphowto/thread/9232ec2c-f787-40f2-83cc-9018d5b3d59f#9232ec2c-f787-40f2-83cc-9018d5b3d59f. You can also use the vieWport meta tag in the html to control the browser's behaviour.

     

    Tuesday, January 17, 2012 2:18 PM
  • Thanks for your reply !
    Right now I am continuing with Web Browser option. It is working fine.
    Thanks!
    Wednesday, January 18, 2012 5:04 AM
  • This is probably resolved, but for people who may run into this in the future. The ImageTools suite uses a lot of memory as it converts the GIF per frame. So if you have multiple GIFs, expect hit the "OutOfMemoryException" often.  I find that the Web Browser method to be the best option IMO.
    Wednesday, January 18, 2012 10:11 AM
  • Actually I am still trying to do it using ImageTool. I have downloaded this dll and added it in my app. But it is giving exception continuously. I am not getting what is happening exactly.
    System.MissingMethodException this exception is coming. I am putting my code please have look. What I am missing if anybody found it plz let me know.
    My Xaml Code:-
    xmlns:imagetools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"  
    --- 
    --- 
    <phone:PhoneApplicationPage.Resources> 
            <imagetools:ImageConverter x:Key="ImageConverter"/> 
        </phone:PhoneApplicationPage.Resources> 
    --- 
    --- 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"
                <imagetools:AnimatedImage Source="{Binding imageSource, Converter={StaticResource ImageConverter}}"/> 
     
            </Grid> 
    My C# Code:-
    --- 
    --- 
    using ImageTools.IO; 
    using ImageTools.IO.Gif; 
    using ImageTools; 
    using ImageTools.Controls; 
    using System.Windows.Media.Imaging; 
    --- 
    --- 
    public MainPage() 
            { 
                InitializeComponent(); 
                Decoders.AddDecoder<GifDecoder>();             
                Loaded += OnPageLoaded;                       
            } 
    void OnPageLoaded(Object sender,RoutedEventArgs e) 
            { 
                Uri u = new Uri("http://61.246.139.125/CMSODP/somnath_ast/21_09_2011_12_24_20/Animations/Animations/content/240x320/Islamic_A_1.gif", UriKind.Absolute); 
                ImageSource imageSource = new BitmapImage(u);             
            } 
    I am trying to resolve this but if anybody can suggest any thing then please do it.
    Thanks in advance!
    Wednesday, January 18, 2012 12:20 PM
  • Hi guys!
    Indeed I need your help because after trying and doing a long time search I am still getting same Exception.
    I have changed my code but there is no result. I can not go with WebBrowser because it is not meet my need. Have a look-
     public MainPage() 
            { 
                InitializeComponent(); 
                Decoders.AddDecoder<GifDecoder>(); 
                WrapPanel wrapPanel = new WrapPanel(); 
                wrapPanel.Children.Add(GetKishna("Krishna.gif"));             
            } 
           private static AnimatedImage GetKrishna(string name) 
           { 
               //Image image = new Image(); 
               ExtendedImage image = new ExtendedImage();//EXCEPTION coming here 
               Uri u = new Uri("Gif/krishna.gif" + name, UriKind.Relative); 
               image.UriSource = u;           
               AnimatedImage krishna = new AnimatedImage(); 
               krishna.Stretch = Stretch.None; 
               krishna.Source = image; 
               return krishna; 
           } 
           
    Right now I am taking only one gif file and I trying it for relative source just to know whether it working or not. Exception is coming where I indicated in the code the text which I am getting is :-
    Could not load type 'System.Diagnostics.Contracts.ContractFailureKind' from assembly 'mscorlib, Version=3.7.0.0, Culture=neutral, PublicKeyToken=969DB8053D3322AC'.
    If anyone can suggest any thing so please do it.

    Thanks for your Support!
    Thursday, January 19, 2012 12:32 PM
  • Hello every one!

    I am still stuck in this problem.
    Any body has any idea about this that is it possible or not. I think it should be possible because now Silverlight also supports the .GIF files. Anybody knows about any  API which supports .GIF files in WP 7?
    :(

    Thanks for your support!!




    Thursday, February 16, 2012 5:20 AM
  • I think it should be possible because now Silverlight also supports the .GIF files.
    Where did you hear that? As far as I know, even the recently released Silverlight 5 only supports jpg and png (Windows Phone is Silverlight 4).


    Richard Woo
    Thursday, February 16, 2012 6:19 AM
  • Hi

    Read this link of CodePlex, I am taking reference of this link.
    http://imagetools.codeplex.com/SourceControl/changeset/view/33161#518787

    That is why I am trying to play .GIF files in WP 7.

    Thanks for support!
    Thursday, February 16, 2012 7:12 AM
  • CodePlex has libraries that can be used on Windows Phone to support GIF files as you mentioned, but that is not an official Silverlight library.  Nothing against you asking the question here, but have you looked at the forums/discussions on the ImageTools.Codeplex page to see if they can help you as well.  You may get more help there.


    Thursday, February 16, 2012 9:20 AM
  • Thanks for reply!
     Yes I posted on CodePlex also but didn't get any reply yet. I am still continue with my search on net.
     
    So should I consider this thing that it is not possible to play GIF files on WP 7 ???

    Thanks!!
    Thursday, February 16, 2012 10:15 AM
  • Umm... it works fine for me.

    2. Open and build the VS solution: /src/ImageTools/ImageTools.Phone.sln
    3. Open the demo project: /src/ImageTools/Demos/ImageTools.Demos.Phone/ImageTools.Demos.Phone.csproj
    4. Expand the References folder. Delete the references that are marked as missing. Add as new references the dlls in the folder /bin/Phone
    5. Build the project and verify that you can run it.
    6. To the Images project folder, add the nine Smiley*.gif images from the folder /src/ImageTools/Demos/ImageTools.Demos/Images
    7. Add this PivotItem to MainPage.xaml
            <controls:PivotItem Header="gif"
                <StackPanel Background="Gray"
                    <it:AnimatedImage x:Name="SmileyCool" Height="20" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyCursing" Height="24" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyDrool" Height="25" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyGrins" Height="18" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyHuh" Height="20" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyJedi" Height="40" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyLol" Height="20" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyLove" Height="18" Margin="10"/> 
                    <it:AnimatedImage x:Name="SmileyWink" Height="20" Margin="10"/> 
                </StackPanel> 
            </controls:PivotItem> 
    8. Add initialization code to the constructor in MainPage.xaml.cs
            public MainPage() 
            { 
                InitializeComponent(); 
     
                ImageTools.IO.Decoders.AddDecoder<ImageTools.IO.Gif.GifDecoder>(); 
     
                SmileyCool.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyCool.gif", UriKind.Relative) }; 
                SmileyCursing.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyCursing.gif", UriKind.Relative) }; 
                SmileyDrool.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyDrool.gif", UriKind.Relative) }; 
                SmileyGrins.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyGrins.gif", UriKind.Relative) }; 
                SmileyHuh.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyHuh.gif", UriKind.Relative) }; 
                SmileyJedi.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyJedi.gif", UriKind.Relative) }; 
                SmileyLol.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyLol.gif", UriKind.Relative) }; 
                SmileyLove.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyLove.gif", UriKind.Relative) }; 
                SmileyWink.Source = new ExtendedImage() { UriSource = new Uri("/Images/SmileyWink.gif", UriKind.Relative) }; 
     
                SmileyCool.Start(); 
                SmileyCursing.Start(); 
                SmileyDrool.Start(); 
                SmileyGrins.Start(); 
                SmileyHuh.Start(); 
                SmileyJedi.Start(); 
                SmileyLol.Start(); 
                SmileyLove.Start(); 
                SmileyWink.Start(); 
            } 
    9. Build and run the app.


    Richard Woo
    Friday, February 17, 2012 8:56 AM
  • Thank you for sharing the info. I was looking for it as well. It works great.

    Vish

    Friday, February 17, 2012 7:36 PM
  • Okay thanks every one!

    Yeh Now its working for me!!
     
    Actually I have old ImageTools source code and making some mistakes in running it. Now I downloaded updated source code and tried it as above explained.

    Thanks for your support!
    Saturday, February 18, 2012 7:30 AM
  • hi friend how did u get the solution for this, now i want to do as same as you in my application at windows phone 7, so please can u help me , pls explain how to do i am in new at windows phone platform

    Thanks in advance


    siva

    Tuesday, May 28, 2013 10:43 AM
  • First get the sample working, then transfer it to your own app.
    Tuesday, May 28, 2013 3:57 PM
  • Thank u for ur Reply, now working well if i give image from server side  but i want to work from local path image that mean load the image from inside the project like jpeg or png format image, i tried this code

     try
                {
                    ImageSource = new Uri("file:///C:/Users/sram.I-WAVES/Desktop/S&L_BB/Dice%20anim/dice_anim_1.gif", UriKind.RelativeOrAbsolute);
                    ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
                    this.DataContext = this;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

    but it throws the Exception like "exception occurred during a WebClient request. how to solve this problem and how to show the image from inside the project ? please help me

             


    siva

    Wednesday, May 29, 2013 8:00 AM
  • Thank u for ur Support but sometime gif image will not be animated during running on the simulator something get stuck, i don't know what is the problem is going on please help me.

    siva

    Wednesday, May 29, 2013 11:21 AM
  • Hi Friend, now working of gif file is fine in my app but i need to stop the gif image at last frame, how to do pls tell me


    siva

    Tuesday, June 04, 2013 10:20 AM

  • This is good but It does not play file with a little large size.. it plays few frames then restarts from the begining...
    Monday, January 13, 2014 8:59 AM