我已经在wpf中创建了一个转换器,该转换器获取字节数组,我想返回图像。返回的图像以xaml的形式绑定到图像控件中。但是在xaml中会发生此错误: NotSupportedException:未找到适合完成此操作的映像组件。
我的转换器在vb.net中:-
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If value Is Nothing Then Return Binding.DoNothing
Return ToBitmapImage(value)
End Function
Private Function ToBitmapImage(ByVal bytes As Byte()) As BitmapSource
Dim bitmapImage As BitmapImage = New BitmapImage()
Using ms As MemoryStream = New MemoryStream(bytes)
ms.Position = 0
bitmapImage.BeginInit()
bitmapImage.CacheOption = BitmapCacheOption.OnLoad
bitmapImage.StreamSource = ms
bitmapImage.EndInit()
End Using
Return bitmapImage
End Function
在XAML中有什么指导方针我错了吗?我已经在中测试了ToBitmapImage()函数,没关系。