【发布时间】:2009-04-28 14:50:01
【问题描述】:
我从 db 获得一个字节数组 (byte[]) 并使用以下方法渲染到图像控件中:
public Image BinaryImageFromByteConverter(byte[] valueImage)
{
Image img = new Image();
byte[] bytes = valueImage as byte[];
MemoryStream stream = new MemoryStream(bytes);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit();
img.Source = image;
img.Height = 240;
img.Width = 240;
return img;
}
现在已经渲染了,我想将 Image.Source 从 Image(控件)“复制”到另一个元素,例如:Paragraph..
paragraph1.Inlines.Add(new InlineUIContainer(ImageOne));
但什么都没有出现,我尝试使用 ImageOne.Source 创建一个新图像,但我刚刚找到了这个带有 Uri(@"path") 的示例,我无法应用此方法,因为我的 BitmapImage 来自 byte[] 类型
Image img = new Image();
img.Source = new BitmapImage(new Uri(@"c:\icons\A.png"));
请帮忙解决这个问题,谢谢!
【问题讨论】:
-
我不建议(反)序列化流中的图像/任何不(反)序列化像素格式、宽度、高度、步幅的图像。 - 这样做是一个漏洞。
-
如果你使用BitmapSource作为图片,你可以读取缓冲区并从缓冲区中创建一个新的BitmapSource。
标签: wpf image-processing