gpt4 book ai didi

c# - 从 sql 数据库中检索图像(字节数组)并显示图像

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:06 25 4
gpt4 key购买 nike

<分区>

在我的 wpf mvvm 应用程序中,我编写了用于图像上传和保存到数据库的代码。代码运行良好,图像保存到数据库中。这里我需要从数据库中检索图像并显示在图像框中。这是我的插入代码

public void Upload(object obj)
{
try
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".png";
dlg.Filter = "Image files (*.png;*.jpg)|*.png;*.jpg";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string filename = dlg.FileName;
UploadText = filename;
FileStream FS = new FileStream(filename, FileMode.Open, FileAccess.Read);
byte[] img = new byte[FS.Length];
FS.Read(img, 0, Convert.ToInt32(FS.Length));
UploadLogo = img;
Stream reader = File.OpenRead(filename);
System.Drawing.Image photo = System.Drawing.Image.FromStream((Stream)reader);
MemoryStream finalStream = new MemoryStream();
photo.Save(finalStream, ImageFormat.Png);
// translate to image source
PngBitmapDecoder decoder = new PngBitmapDecoder(finalStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.Default);
ClientLogo = decoder.Frames[0]; ;
}
}

catch (Exception ex)
{
throw ex;
}
}

我怎样才能将这个字节数据转换成图像

提前致谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com