2012-04-03 44 views
0

我正在从WP7中获取联系人。一些联系人有图像一些没有。我想显示那些没有图像的联系人的默认图像。从WP7中的图像返回DecodeJpeg

我用下面的图像转换器,

public class ContactPictureConverter : System.Windows.Data.IValueConverter 
    { 
     public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
     { 
      Contact c = value as Contact; 
      if (c == null) return null; 

      System.IO.Stream imageStream = c.GetPicture(); 


      if (null != imageStream) 
      { 
       return Microsoft.Phone.PictureDecoder.DecodeJpeg(imageStream); 
      } 
      else 
      { 
       return null; 
      } 
     } 

在如果的ImageStream是空的话,我想回到我的默认图像。

如何做到这一点?

回答

1

您可以在项目的App类中使用共享变量,您可以在转换器中引用该变量。

或者更好,建议您只需使用BitmapSource,其相对URL指向您的资源图像。

BitmapImage

var bitmapImage = new BitmapImage 
          { 
           UriSource = 
            new Uri("../Images/Test.JPG", UriKind.Relative) 
          }; 

或VB

Dim bitmapImage = New BitmapImage() With { _ 
    Key .UriSource = New Uri("../Images/Test.JPG", UriKind.Relative)} 
+0

谢谢Nasenbaer ......它的工作好... :-) – Ponmalar 2012-04-03 06:48:22