2012-04-03 12 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がnullの場合は、その後、私は私のデフォルトの画像を返すようにしたいです。

これを行う方法?

答えて

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

関連する問題