将图像的字节数组从MemoryStream分配给图像 [英] Assigning Byte Array of Image from MemoryStream to Image
问题描述
你好
我正在获取图像的字节数组,我正在使用MemoryStream
I am getting the Bytearray of Image, I am Using the MemoryStream
,然后将Memorystream分配给Bitmap对象StreamSource.然后分配
and Assigning the Memorystream to Bitmap object StreamSource and after that assigning
ImageSource的位图对象我没有收到任何错误,但也看不到图像
Bitmap object to ImageSource I am not getting any error but also not able to see Image
下面是我的代码.
使用(var stream = new MemoryStream(userPhto1.photo.ToArray()))
{
] stream.Seek(0,SeekOrigin.Begin);
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.DecodePixelWidth = 200;
bitmap.StreamSource =流;
stream.Close();
bitmap.EndInit();
photoUser.Source =位图; //PhotoUser的类型为图像
]
}
using (var stream = new MemoryStream(userPhto1.photo.ToArray()))
{
stream.Seek(0, SeekOrigin.Begin);
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.DecodePixelWidth = 200;
bitmap.StreamSource = stream;
stream.Close();
bitmap.EndInit();
photoUser.Source = bitmap; // PhotoUser Is of Type Image
}
有人能帮助我吗?
推荐答案
gloglotan
hi glochetan
请看看这个:
http://stackoverflow.com/questions/2097152/creating-wpf -bitmapimage-from-memorystream-png-gif
这篇关于将图像的字节数组从MemoryStream分配给图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!