我正在尝试将 byte[] 绑定到图像控件中,但转换器中存在一些问题。请让我知道我该如何解决这个问题?stream.WriteAsync(bytesArray.AsBuffer());
由于 byte[] 中没有 AsBuffer 函数,我在线遇到错误 。我应该如何解决这个问题?
代码:
public object Convert(object value, Type targetType, object parameter, string language)
{
byte[] bytesArray;
if (value != null && value is byte[] && (value as byte[]).Length > 0)
{
bytesArray = value as byte[];
}
else
{
//TODO: Add default Image here
}
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
BitmapImage image = new BitmapImage();
stream.WriteAsync(bytesArray.AsBuffer());
stream.Seek(0);
image.SetSource(stream);
return image;
}
}
XAML 代码:
<Image Source="{Binding Path=OnlineBooksDetail[0].ImageSource, Converter={StaticResource ByteToBitmapImageConverter}}" Width="407" Height="542">
</Image>