如何在数据库mysql中保存的图片框中显示图像? [英] how to show image in picture box which is saved in database mysql?

查看:128
本文介绍了如何在数据库mysql中保存的图片框中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MemoryStream mstream = new MemoryStream(img);

pictureBox1.Image = System.Drawing.Image.FromStream(mstream);

在第二行,我必须面对一个无效参数的异常。请帮助我。

我的字段数据类型是blob,我必须在c#project中显示这张图片。

解决方案

请参阅此处:为什么选择我得到一个参数无效。我从数据库中读取图像时出现异常? [ ^ ] - 它是基于Sql Server的,但它与MySql的问题(和解决方案)完全相同。


  string  query1 =  从ID ='的成员中选择*; 
query1 = query1 + txtid.Text + ';
cmd = new MySqlCommand(query1,con);
MySqlDataReader d1 = cmd.ExecuteReader();
while (d1.Read())
{
try
{
byte [] data =( byte [])d1 [< span class =code-string> image];
使用(MemoryStream stream = new MemoryStream(data))
{
pictureBox1.Image = new 位图(流);
}


看看下面的文章。



从SQL服务器显示图像



我希望它能解决你的问题。 :)

MemoryStream mstream = new MemoryStream(img);
pictureBox1.Image = System.Drawing.Image.FromStream(mstream);
At the second line i have to face an exception that invalid parameter.Kindly help me.
my field data type is blob and i have to show this picture in c# project.

解决方案

See here: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - it's Sql Server based, but it's exactly the same problem (and solution) with MySql.


string query1 = "Select * from members where ID='";
           query1 = query1 + txtid.Text + "'";
           cmd = new MySqlCommand(query1, con);
           MySqlDataReader d1 = cmd.ExecuteReader();
           while (d1.Read())
           {
               try
               {
                   byte[] data = (byte[])d1["image"];
                   using (MemoryStream stream = new MemoryStream(data))
                   {
                       pictureBox1.Image = new Bitmap(stream);
                   }


Do have a look at the following article.

Display Images from SQL server

I hope it will solve your problem. :)


这篇关于如何在数据库mysql中保存的图片框中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆