如何从byte []创建FileStreame? [英] How to Create FileStreame from byte[]?
本文介绍了如何从byte []创建FileStreame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的班级:
class person
{
public string Name{get;set;}
public byte[] PersonImage{get;set;}
}
当我从数据库中加载Person时,我想在Image控件中显示PersonImage,所以我想从我的byte []中创建BitmapImage:
When I Load my Person From DataBase I want to show PersonImage in a Image control, so I want to create BitmapImage from my byte[]:
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
var filestream = new MemoryStream(PersonImage);
bitmapImage.StreamSource = filestream;
bitmapImage.EndInit();// I have Exception in this line
我的例外是:
未找到适合完成此操作的成像组件.
No imaging component suitable to complete this operation was found.
-有礼 我的内部异常是:
--edite my Inner Exception is :
内部异常:HRESULT:0 * 88982F50的异常
Inner Exception:Exception from HRESULT:0*88982F50
推荐答案
假定PersonImage
实际上是表示图像尝试的有效byte[]
assuming PersonImage
is really a valid byte[]
representing an image try
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
var somestream = new MemoryStream(PersonImage);
somestream.Position = 0; // "rewind" stream to start...
bitmapImage.StreamSource = somestream;
bitmapImage.EndInit();
这篇关于如何从byte []创建FileStreame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文