我正在尝试将来自MySQL数据库的BLOB数据转换为Base64,然后将其显示为jpg图像..这是我正在使用的代码:
using (MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection("S;Port=P;Database=DB;Uid=U;Pwd=P"))
{
connection.Open();
MySql.Data.MySqlClient.MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "SELECT blobValue FROM Table WHERE blob_id = '333'";
MySql.Data.MySqlClient.MySqlDataReader datr = cmd.ExecuteReader();
if (datr.Read())
{
byte[] xx = (byte[])datr.GetValue(0);
string base64String = Convert.ToBase64String(xx, 0, xx.Length);
Image1.ImageUrl = "data:image/jpg;base64," + base64String;
}
我想我的代码没有问题,但是在运行代码时,我得到一张空图片,就像这个一样 - >
请一些帮助。