Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从mysql数据库中检索图像?_C#_Mysql - Fatal编程技术网

C# 如何从mysql数据库中检索图像?

C# 如何从mysql数据库中检索图像?,c#,mysql,C#,Mysql,我已经使用以下命令将图像存储到mysql中,现在我想检索。。。我想将ny图像从字节转换为图像,然后显示它。。。我该怎么做 public void LoadImages() { byte[] ImageData; string image = txtLogo.Text; FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read); Bina

我已经使用以下命令将图像存储到mysql中,现在我想检索。。。我想将ny图像从字节转换为图像,然后显示它。。。我该怎么做

public void LoadImages()
        {
        byte[] ImageData;
        string image = txtLogo.Text;
        FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);
        ImageData = BitConverter.GetBytes(fs.Length);                                    
        string query = "insert into Fn_Pictures(Images,Email)values(@Images,'" + txtEmailId.Text + "')";
        MySqlConnection con = new MySqlConnection(connstring);
        MySqlCommand cmd = new MySqlCommand(query, con);
        MySqlDataReader myReaeder;
        con.Open();
        myReaeder = cmd.ExecuteReader();

    }     

在数据库中存储图像是一种完全的开销。 只需将它们保存在磁盘上,速度会快得多


如果要存储图像,请使用blob,您需要为图像创建一个不同的页面,并显示正确的标题。

要存储图像,请存储在磁盘上


您只需将图像路径保存在数据库中或仅保存图像名称,通过动态编码您可以检索图像的绝对路径,这将比任何技术都快得多

如何更快?为什么更快?嘿@草莓你能给我一个更快的答案吗?因为:你不能只选择图片并打印在你的页面上。您的web服务器会对图像进行缓存,浏览器也会进行缓存(第2次访问通常图像不会重新下载=节省大量流量),仅因为这样,我才不会存储它。Allso您正在使您的行变大=较慢的数据库对不起,lampdev我一直在使用C#这可以与任何编程语言无关