I want to download a GIF from a URL and save to isolated storage for WP8. I have been trying to use the imagetools library to decode the GIF then convert into a jpeg as silverlight does not support gifs and i want to display the saved image later using the webbrowser control. My code:
ExtendedImage image = new ExtendedImage();
image.LoadingFailed += image_LoadingFailed;
image.LoadingCompleted += (sender, e) =>
{
var isoStore = IsolatedStorageFile.GetUserStoreForApplication();
if (filename.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))
{
GifDecoder gifdecoder = new GifDecoder();
JpegEncoder jpegencoder = new JpegEncoder();
using (var stream = new IsolatedStorageFileStream("somefolder/" + filename, FileMode.Create, isoStore))
{
gifdecoder.Decode(image, stream);
BitmapImage bitmap = new BitmapImage();
using (MemoryStream stream2 = new MemoryStream())
{
jpegencoder.Encode(image, stream2);
bitmap.SetSource(stream2);
}
}
}
image.UriSource = new Uri(imageurl, UriKind.Absolute);