简体   繁体   English

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

[英]How to retrieve image from mysql database?

I have stored image into mysql using following and now i want to retrieve... I want to convert ny image from bytes to image and then display it ... how can i do that 我已经使用以下方法将图像存储到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();

    }     

It's a complete overhead to store images in a database. 将图像存储在数据库中是完全的开销。 Just save them on the disk, it's a lot faster. 只需将它们保存在磁盘上,速度会更快。

If you want to store them use blob, and you will need a different page for the image, with the right headers to display it. 如果要存储它们,请使用blob,并且图像将需要另一个页面,并带有正确的标题来显示它。

In order to store images , store on disk 为了存储图像,存储在磁盘上

All you has to do is save the image path in Database or just image name and through dynamic coding you can retrieve absolute path of image , This would be much more faster , irespective of any technology 您所要做的就是将图像路径保存在数据库中或仅保存图像名称,并通过动态编码可以检索图像的绝对路径,无论使用哪种技术,这都将更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM