System.NotSupportedException HResult = 0x80131515消息=找不到适合完成此操作的映像组件

时间:2019-05-19 11:44:40

标签: c# wpf

  1. 我正在保存图像并从sql server 2017中检索图像,当我正在检索异常显示时

  2. 错误“ System.NotSupportedException HResult = 0x80131515 Message =未找到适合完成此操作的成像组件”

  3. Microsoft SQL Server Studio 2017

  4. 以下是用于从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,但是我无法理解为什么会发生

0 个答案:

没有答案