注册 登录
编程论坛 C# 论坛

pictureBox1.Image = Image.FromStream(ms)出错(参数无效)

jack_xu2046 发布于 2010-10-01 22:44, 5502 次点击
            string sql = "select cid,img from PicTable order by cid";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
            DataSet dataSet = new DataSet();
            dataAdapter.Fill( dataSet , "BLOBTEST");
            int c = dataSet.Tables["BLOBTEST"].Rows.Count;
            try
            {
                if (c > 0)
                {
                    byte[] mybyte = new byte[0];
                    mybyte = (Byte[])(dataSet.Tables["BLOBTEST"].Rows[c - 1]["img"]);
                    MemoryStream ms = new MemoryStream(mybyte);//此处没有问题。可以读到mybyte数组
                    pictureBox1.Image = Image.FromStream(ms);
                }
                con.Close();
            }

好无奈,好多地方看到都是这样写的,不清楚为什么会出错。

[ 本帖最后由 jack_xu2046 于 2010-10-1 22:51 编辑 ]
3 回复
#2
gameohyes2010-10-01 23:48
可能是保存的时候,没有保存好.或者保存方式错误
详情请参见:
https://down.bccn.net/404.html
#3
jack_xu20462010-10-02 00:09
            string filePath = @"C:\Documents and Settings\xuyadong\桌面\Esic\Esic\Shining.jpg";

            FileStream fileByte = File.Open(filePath, FileMode.Open, FileAccess.Read);
            BinaryReader bytes = new BinaryReader(fileByte);
            
            byte[] photo = bytes.ReadBytes((int) fileByte .Length);
丢死人了。
fileByte竟然写成filepath了。怪不得!

[ 本帖最后由 jack_xu2046 于 2010-10-2 00:49 编辑 ]
#4
Askla2014-08-02 20:20
。。。
1