<small id='ATxbM'></small><noframes id='ATxbM'>

      <bdo id='ATxbM'></bdo><ul id='ATxbM'></ul>
  1. <tfoot id='ATxbM'></tfoot>

      <i id='ATxbM'><tr id='ATxbM'><dt id='ATxbM'><q id='ATxbM'><span id='ATxbM'><b id='ATxbM'><form id='ATxbM'><ins id='ATxbM'></ins><ul id='ATxbM'></ul><sub id='ATxbM'></sub></form><legend id='ATxbM'></legend><bdo id='ATxbM'><pre id='ATxbM'><center id='ATxbM'></center></pre></bdo></b><th id='ATxbM'></th></span></q></dt></tr></i><div id='ATxbM'><tfoot id='ATxbM'></tfoot><dl id='ATxbM'><fieldset id='ATxbM'></fieldset></dl></div>
    1. <legend id='ATxbM'><style id='ATxbM'><dir id='ATxbM'><q id='ATxbM'></q></dir></style></legend>

    2. 将图像从 WPF 控件保存到 SQL Server DB

      时间:2023-06-06

          <legend id='NZiyA'><style id='NZiyA'><dir id='NZiyA'><q id='NZiyA'></q></dir></style></legend>
        1. <small id='NZiyA'></small><noframes id='NZiyA'>

          <tfoot id='NZiyA'></tfoot>

            <bdo id='NZiyA'></bdo><ul id='NZiyA'></ul>

              <i id='NZiyA'><tr id='NZiyA'><dt id='NZiyA'><q id='NZiyA'><span id='NZiyA'><b id='NZiyA'><form id='NZiyA'><ins id='NZiyA'></ins><ul id='NZiyA'></ul><sub id='NZiyA'></sub></form><legend id='NZiyA'></legend><bdo id='NZiyA'><pre id='NZiyA'><center id='NZiyA'></center></pre></bdo></b><th id='NZiyA'></th></span></q></dt></tr></i><div id='NZiyA'><tfoot id='NZiyA'></tfoot><dl id='NZiyA'><fieldset id='NZiyA'></fieldset></dl></div>
                  <tbody id='NZiyA'></tbody>
              • 本文介绍了将图像从 WPF 控件保存到 SQL Server DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个用 WPF 3.5 编写的应用程序,它在某些时候将数据保存在 SQL Server 中包含图像中,这是保存数据的代码的一部分(注意 this.pictureImage 是一个 WPF Image 控件):-

                I have an application written in WPF 3.5 which at some point it saves the data in including an image in SQL Server, this is part of the code in saving the data (note this.pictureImage is a WPF Image control):-

                using (SqlCommand command = myConnection.CreateCommand())
                {
                    String sqlInsertCommand = "INSERT INTO Info_Id (idNumber, FirstName, Nationality, Image) VALUES (@idNumber, @firstName, @nationality, @image)";
                
                    command.CommandText = sqlInsertCommand;
                    command.CommandType = System.Data.CommandType.Text;
                
                    command.Parameters.AddWithValue("@idNumber", this.cardIdTextBlock.Text);
                    command.Parameters.AddWithValue("@firstName", this.fullNameTextBlock.Text);
                    command.Parameters.AddWithValue("@nationality", this.nationaltyTextBlock.Text);
                    command.Parameters.AddWithValue("@image", this.pictureImage);
                
                    command.ExecuteNonQuery();
                }
                

                运行此程序并单击保存到数据库按钮后,出现以下错误.

                After I run this and click on the saving to DB button I got the following error.

                不存在从对象类型 System.Windows.Controls.Image 到已知托管提供程序的映射

                No mapping exists from object type System.Windows.Controls.Image to a known managed provider

                在 SQL Server 数据库中,我有一行 (Picture (Image, null)).

                In the SQL Server database I have a row with (Picture (Image, null)).

                请多多指教.谢谢.

                推荐答案

                您无法在数据库中保存 Image 控件.相反,您应该通过适当的位图编码器在 Image 控件的 Source 属性中对图像进行编码,并将编码的缓冲区存储为字节数组.

                You can't save an Image control in your database. Instead you should encode the image in the Image control's Source property by an appropriate bitmap encoder and store the encoded buffer as byte array.

                byte[] buffer;
                var bitmap = pictureImage.Source as BitmapSource;
                var encoder = new PngBitmapEncoder(); // or one of the other encoders
                encoder.Frames.Add(BitmapFrame.Create(bitmap));
                
                using (var stream = new MemoryStream())
                {
                    encoder.Save(stream);
                    buffer = stream.ToArray();
                }
                
                // now store buffer in your DB
                

                这篇关于将图像从 WPF 控件保存到 SQL Server DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何替换SQL中的部分字符串 下一篇:WSO2 API Manager 身份验证违反 UNIQUE KEY 约束错误

                相关文章

                最新文章

                <legend id='A9rUH'><style id='A9rUH'><dir id='A9rUH'><q id='A9rUH'></q></dir></style></legend>
                  <bdo id='A9rUH'></bdo><ul id='A9rUH'></ul>

                <tfoot id='A9rUH'></tfoot>
                <i id='A9rUH'><tr id='A9rUH'><dt id='A9rUH'><q id='A9rUH'><span id='A9rUH'><b id='A9rUH'><form id='A9rUH'><ins id='A9rUH'></ins><ul id='A9rUH'></ul><sub id='A9rUH'></sub></form><legend id='A9rUH'></legend><bdo id='A9rUH'><pre id='A9rUH'><center id='A9rUH'></center></pre></bdo></b><th id='A9rUH'></th></span></q></dt></tr></i><div id='A9rUH'><tfoot id='A9rUH'></tfoot><dl id='A9rUH'><fieldset id='A9rUH'></fieldset></dl></div>

                    <small id='A9rUH'></small><noframes id='A9rUH'>