我正在保存图像并从sql server 2017中检索图像,当我正在检索异常显示时
错误“ System.NotSupportedException HResult = 0x80131515 Message =未找到适合完成此操作的成像组件”
Microsoft SQL Server Studio 2017
以下是用于从sql server 2017检索图像的代码块
SqlConnection con;
String sqlstr = "select photo from img Where itmNO='" + txt1.Text + "'";
string conString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
con = new SqlConnection(conString);
con.Open();
SqlCommand cmd1 = new SqlCommand(sqlstr, con);
object value = cmd1.ExecuteScalar();
byte[] imageData = (byte[])value;
if (imageData != null && imageData.Length > 0)
{
var imag = new BitmapImage();
using (var mem = new MemoryStream(imageData))
{
mem.Position = 0;
mem.Write(imageData, 0, imageData.Length - 0);
imag.BeginInit();
imag.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
imag.CacheOption = BitmapCacheOption.OnLoad;
imag.UriSource = null;
imag.StreamSource = mem;
imag.EndInit();
}
imag.Freeze();
img2.Source = imag;
}
5。提前谢谢 当我保存字节数组时,字节长度显示为84254,但是在检索时,它的长度仅显示13,但是我无法理解为什么会发生