C# 如何从Mysql中检索图像并在图像控件asp.net中直接读取

C# 如何从Mysql中检索图像并在图像控件asp.net中直接读取,c#,mysql,asp.net,image,C#,Mysql,Asp.net,Image,我在MySQL中以byte[]数组的形式将图像存储为blob数据类型,但在image control中的asp.net应用程序中,我找不到以其他方式读取相同图片的正确方法。在“slike”表中有3列-image、imagename、brTablice-我搜索了很长时间的答案,但没有找到任何答案。这是我的密码: protected void Button1_Click(object sender, EventArgs e) { string connectionString = "Serv

我在MySQL中以byte[]数组的形式将图像存储为blob数据类型,但在image control中的asp.net应用程序中,我找不到以其他方式读取相同图片的正确方法。在“slike”表中有3列-image、imagename、brTablice-我搜索了很长时间的答案,但没有找到任何答案。这是我的密码:

protected void Button1_Click(object sender, EventArgs e)
{
    string connectionString = "Server=localhost;Uid=Aleksa;port=3306;Pwd=pass;Database=projekat_automobili;";
    MySqlConnection con = new MySqlConnection(connectionString);
    MySqlCommand cmd = new MySqlCommand("SELECT image from slike where brTablice = 'BG-456-SD'", con);
    con.Open();
    MySqlDataReader DR1 = cmd.ExecuteReader();
    if (DR1.Read())
    {
        //TextBoxJmbg.Text = DR1.GetString(DR1.GetOrdinal("jmbg"));
        //TextBoxIP.Text = DR1.GetString(DR1.GetOrdinal("imeprezime"));
        //TextBoxTel.Text = DR1.GetString(DR1.GetOrdinal("tel"));

        byte[] imgg = (byte[])(DR1["image"]);
        if (imgg == null)
        {
            MemoryStream mstream = new MemoryStream(imgg);
            Image1.ImageUrl = System.Drawing.Image.FromStream(mstream).ToString();
            Image1.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(imgg);
            //Image1.ImageUrl = "";
        }
        else
        {
            MemoryStream mstream = new MemoryStream(imgg);
            Image1.ImageUrl = System.Drawing.Image.FromStream(mstream).ToString();
        }
    }


    con.Close();
}

这是项目的一部分

mysql表:

----------------------------
G_Picture| G_Picture_size |
----------------------------
0xsd/s45e| 9000           |
-----------------------------

uint FileSize = _sqldatareader.GetUInt32(_sqldatareader.GetOrdinal("G_Picture_size"));
                byte[] rawData = new byte[FileSize];
                _sqldatareader.GetBytes(_sqldatareader.GetOrdinal("G_Picture"), 0, rawData, 0, (Int32)FileSize);
                MemoryStream ms = new MemoryStream(rawData);
                __G_Picture.BackgroundImage = new Bitmap(ms);
现在您可以创建位图图片。 希望这能奏效