[英]How to convert Blob value to Image
I have a BLOB value in a MySQL database. 我在MySQL数据库中有一个BLOB值。
I've read several tutorials, but I can not find a solution. 我已经阅读了一些教程,但是找不到解决方案。
Any idea how I can read the image (blob value) and view it in an ASP.NET Image component? 知道如何读取图像(blob值)并在ASP.NET Image组件中查看吗?
All info i found is about array convert to image, but I have a Blob value 我发现的所有信息都是关于数组转换为图像的,但是我有一个Blob值
Did you try to read the image from db and put in a MemoryStream, then show it in an image component? 您是否尝试从db读取图像并将其放入MemoryStream,然后在图像组件中显示它? Something like :
就像是 :
Byte[] byteBLOBData = new Byte[bufferSize];
byteBLOBData = "read image from database"
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
pictureBox.Image = Image.FromStream(stmBLOBData);
Reference : https://bytes.com/topic/c-sharp/answers/965811-retrieve-blob-picture-mysql-database-c 参考: https : //bytes.com/topic/c-sharp/answers/965811-retrieve-blob-picture-mysql-database-c
Problem solved. 问题解决了。
The exact problem was the query... 确切的问题是查询...
Code finished... 代码完成...
Image picture = new Image();
string queryImage = "SELECT image FROM news WHERE id = @id";
using (MySqlConnection con1 = new MySqlConnection(servidor))
{
MySqlCommand cmd1 = new MySqlCommand(queryImage, con1);
cmd1.Parameters.AddWithValue("@id", rd[0]);
con1.Open();
byte[] bytesImage = (byte[])cmd1.ExecuteScalar();
picture.ImageUrl = "data:image;base64," + Convert.ToBase64String(bytesImage);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.