0

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.

Community
  • 1
  • 1
Jane Wayne
  • 535
  • 9
  • 21
  • by the way, i did try this api from http://imagetools.codeplex.com. however, the wp7 DLLs did not have a JPG encoder, so the control can display GIFs, but not JPGs. – Jane Wayne Feb 09 '12 at 00:55
  • what a pain. wp7 should know that GIFs are very popular and still around. on the other hand, facebook should know to be consistent (either all JPGs or all GIFs). i sure wished wp7 supported GIFs out of the box and that facebook was more consistent with their images. – Jane Wayne Feb 09 '12 at 01:08
  • i don't think i have enough points to do that yet chris. :( in fact, i tried that first. – Jane Wayne Feb 09 '12 at 11:19

1 Answers1

2

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

Pavan Kumar
  • 206
  • 1
  • 3