Windows phone 7 从WP7中的图像返回解码JPEG
我正在从WP7检索联系人。有些联系人具有图像,有些联系人没有图像。我想显示那些没有图像的联系人的默认图像 我使用了以下图像转换器Windows phone 7 从WP7中的图像返回解码JPEG,windows-phone-7,Windows Phone 7,我正在从WP7检索联系人。有些联系人具有图像,有些联系人没有图像。我想显示那些没有图像的联系人的默认图像 我使用了以下图像转换器 public class ContactPictureConverter : System.Windows.Data.IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.Cult
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,那么我希望返回默认图像
如何做到这一点?您可以在项目的
App
类中使用共享变量,您可以在转换器中引用该变量
或者更好的建议是,您只需使用BitmapSource
,并将相对URL与您的ressource图像关联
或VB
var bitmapImage = new BitmapImage
{
UriSource =
new Uri("../Images/Test.JPG", UriKind.Relative)
};
Dim bitmapImage = New BitmapImage() With { _
Key .UriSource = New Uri("../Images/Test.JPG", UriKind.Relative)}