如何在 Windows Phone 7 中显示 gif 图像? [英] how to display a gif image in windows phone 7?

查看:25
本文介绍了如何在 Windows Phone 7 中显示 gif 图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Facebook 加载图片.如果用户设置了头像,则图片为jpg,如果用户未设置,则图片为gif格式的存根图片.我知道 wp7 不支持显示 gif 图像(开箱即用).有没有办法检测最终图片是否为gif?

例如,我制作了这样的 BitmapImage:

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

对于这个 uri,用户没有个人资料图片.所以我被带到 https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif.

如果用户确实有图片,那么我按如下方式请求它.

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

对于上述网址,我被带到这样的网址:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/000000_1621037713_00000000_q.jpg

我的问题是,一旦我获得了 BitmapImage 对象 img,我可以确定这是 JPG 还是 GIF?如果是 gif,我可以将其转换为 JPG 吗?

我查看了一些相关问题,但讨论的 API 是异步加载图像的,这不是我目前想要的.此外,文档也很差.

感谢任何帮助.

没关系,我按照这里的说明操作:在 WP7 中显示 GIFSilverlight 应用程序.用户进行了出色的演练.

  1. 在执行此用户建议的操作之前,您需要做的是从 codeplex 下载源代码.

  2. 然后您需要从 http://bitmiracle.com/libjpeg/ 下载 BitMiracle 的 JPEG 库.一>.

  3. 继续进入/src/ImageTools 目录并打开 ImageTools.Phone.sln.将 ImageTools.IO.Jpeg.Phone 项目添加到解决方案中.

  4. 当您构建解决方案时,它会抱怨找不到 BitMiracle 的 JPEG dll,请继续为 Jpeg 项目引用该 DLL.再次构建,它应该可以工作了.

解决方案

首先使用Httprequest或Webclient下载图片(任何),然后通过以下方式将gif(如果是gif)转换为jpg或png.

>

 GifDecoder gd = new GifDecoder();ImageTools.ExtendedImage img = new ImageTools.ExtendedImage();gd.Decode(img, 流);//stream 表示图像流PngEncoder png = new PngEncoder();png.Encode(img, isoFileStreamdownload);//isoFileStreamdownload 表示流,用于将图像保存在图像文件中 like(image.png))

使用 ImageTools.dll、ImageTools.IO.Gif.dll、ImageTools.IO.Png.dll(图像工具)

我觉得对你有帮助

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.

解决方案

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

这篇关于如何在 Windows Phone 7 中显示 gif 图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆