在Windows Phone 7应用程序中动态显示任何类型的图像 [英] Dynamic display of images of any type in windows phone 7 app

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

问题描述

大家好,


我一直在使用windows phone 7 app。我用以下代码来显示任何 我们正在从网络服务中读取以动态显示的图像类型。


  List< BitmapImage>的ImageList =新列表与LT;的BitmapImage>();

&NBSP;串imageModified = QUOT; PNG,PNG,JPG,JPG,BMP,BMP,GIF,GIF,JPEG,JPEG英寸;



     的foreach(ResponseProcessor.WebMethodReturnTypes.AdvertisementList advertisementList在advertisementListStore)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; string fileex = System.IO.Path.GetExtension(advertisementList.fileName).Substring(1);
$


        ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(imageModified.Contains(fileex))

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; urlList.Add(advertisementList.advertiserLink);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(advertisementList.advertiserImage!= NULL)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;字节[] imageByteStoreSelected = Convert.FromBase64String(advertisementList.advertiserImage);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; VAR imageMemoryStream =新的MemoryStream(imageByteStoreSelected);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的BitmapImage btImage =新的BitmapImage();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; btImage.SetSource(imageMemoryStream);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; ImageList.Add(btImage);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; imageMemoryStream.Close();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; }
                    }


此代码以前工作正常。但是当我们添加一个png类型的动画图像时,它在行上显示异常


btImage.SetSource(imageMemoryStream);


"请求不受支持。"


有人可以建议我上面代码中的问题或建议我某种方式尽快克服此异常。


谢谢,


Nibi




解决方案


由于是动画图像,您可以直接指定图像控件。在初始化为图像控制之前应使用解码器

  ImageTools    IO   解码器   AddDecoder  <   GifDecoder   http:// stackoverflow。 COM /问题/ 8960970 /如何-DO-显示-A-GIF-ON-Windows的电话时,呼叫-A-的StaticResource   

Hi all,

I have been working on windows phone 7 app.The following code I am using to display any  type of image we are reading from web service to display dynamically.

 List<BitmapImage> ImageList = new List<BitmapImage>();
 string imageModified = "png,PNG,jpg,JPG,bmp,BMP,gif,GIF,jpeg,JPEG";

      foreach (ResponseProcessor.WebMethodReturnTypes.AdvertisementList advertisementList in advertisementListStore)
                    {
                        string fileex = System.IO.Path.GetExtension(advertisementList.fileName).Substring(1);

                        if (imageModified.Contains(fileex))
                        {
                            urlList.Add(advertisementList.advertiserLink);
                            if (advertisementList.advertiserImage != null)
                            {
                                byte[] imageByteStoreSelected = Convert.FromBase64String(advertisementList.advertiserImage);
                                var imageMemoryStream = new MemoryStream(imageByteStoreSelected);
                                BitmapImage btImage = new BitmapImage();
                                btImage.SetSource(imageMemoryStream);
                                ImageList.Add(btImage);
                                imageMemoryStream.Close();
                            }
                        }
                    }

This code was working fine previously. But when we add an animated image of type png its showing exception on the line

btImage.SetSource(imageMemoryStream);

that "The request is not supported."

Can anyone suggest me what is the issue in the above code or suggest me some way to overcome this exception ASAP.

Thanks,

Nibi

解决方案

Hi,

As it is animated image, you can directly assign to image control. You should use the decoder before you initialize to image control

ImageTools.IO.Decoders.AddDecoder<GifDecoder>();

Also check this link-

http://stackoverflow.com/questions/8960970/how-do-i-display-a-gif-on-windows-phone-when-calling-a-staticresource


这篇关于在Windows Phone 7应用程序中动态显示任何类型的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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