how to display a gif image in windows phone 7?

2019-09-12 12:43发布

问题:

i am trying to load images from facebook. if a user has set a profile picture, then the picture is a jpg, however, if a user has not set one, then the picture is a stub image in gif format. i know that wp7 does not support displaying gif images (out of the box). is there any way to detect if the final picture is a gif or not?

for example, i make a BitmapImage like this:

BitmapImage img = new BitmapImage(new Uri("https://graph.facebook.com/userid1/picture"))

for this uri, the user does not have a profile picture. so i get taken to a stub gif image at https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif.

if a user does have an image, then i request it as follows.

BitmapImage img = new BitmapImage(new Uri("https://graph.facebook.com/userid2/picture"))

for the above url i get taken to a url like this: https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/000000_1621037713_00000000_q.jpg

my question is then, once i get the BitmapImage object, img, can i determine if this is a JPG or GIF? can i convert it to a JPG if it is a gif?

i looked at some related questions, but the API discussed loaded the image asynchronously, which is not what i wanted at the moment. furthermore, there was poor documentation.

any help is appreciated.

nevermind, i followed the instructions here: Display GIF in a WP7 application with Silverlight. the user gave an excellent walk through.

  1. what you need to do before you do what this user suggested is to download the source code from codeplex.

  2. then you need to download BitMiracle's JPEG library from http://bitmiracle.com/libjpeg/.

  3. go ahead and go into the /src/ImageTools directory and open up ImageTools.Phone.sln. add the ImageTools.IO.Jpeg.Phone project to the solution.

  4. when you build the solution it will complain about not finding BitMiracle's JPEG dll, go ahead and reference that DLL for the Jpeg project. build again, and it should work.

回答1:

First download the image(any) using Httprequest or Webclient and then convert to jpg or png from gif(if it is gif) in the following way.

 GifDecoder gd = new GifDecoder();
 ImageTools.ExtendedImage img = new ImageTools.ExtendedImage();
 gd.Decode(img, stream);              //stream means image stream
 PngEncoder png = new PngEncoder();
 png.Encode(img, isoFileStreamdownload);  //isoFileStreamdownload means stream, which is used to save image in image file like(image.png))

using ImageTools.dll, ImageTools.IO.Gif.dll,ImageTools.IO.Png.dll (Images Tools)

I think it helps to you