fma*_*ma3 16 c# wpf bitmapimage
我需要帮助,我有这个方法从Byte []获取BitmapImage
public BitmapSource ByteToBitmapSource(byte[] image)
{
BitmapImage imageSource = new BitmapImage();
using (MemoryStream stream = new MemoryStream(image))
{
stream.Seek(0, SeekOrigin.Begin);
imageSource.BeginInit();
imageSource.StreamSource = stream;
imageSource.CacheOption = BitmapCacheOption.OnLoad;
imageSource.EndInit();
}
return imageSource;
}
Run Code Online (Sandbox Code Playgroud)
imageSource.EndInit();
抛出错误"我们发现没有适合完成此操作的成像组件."
ast*_*ght 26
Image.Source
在XAML中设置为字节数组属性.
<Image x:Name="MyImage" Source="{Binding Path=MyByteArrayProperty}" />
Run Code Online (Sandbox Code Playgroud)
如果你真的想要你可以在这样的代码背后做到这一点
public void DecodePhoto(byte[] byteVal)
{
MemoryStream strmImg = new MemoryStream(byteVal);
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.StreamSource = strmImg;
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
MyImage.Source = myBitmapImage;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20640 次 |
最近记录: |