图片img = Image.FromStream(strm); //无效的参数 [英] Image img = Image.FromStream(strm); //invalid parameter

查看:119
本文介绍了图片img = Image.FromStream(strm); //无效的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我从sql图片的sql服务器中检索签名时,就像...

Hi guys when i retrieving the signature from sql server of ink picture which i have inserted like...

string rowsid = GlobalClass.rowsID;
image.Save(Application.StartupPath + @"\Signature\" + "Out" + "+" + GlobalClass.RepName + "+" + rowsid + ".JPG");


并尝试从sql server中检索,例如...


and trying to retrieve from sql server like...

if (dr.Read())
{
    textBox2.Text = dr[7].ToString();
    textBox5.Text = dr[12].ToString();
    textBox3.Text = dr[10].ToString();
    textBox4.Text = dr[11].ToString();
    
    byte[] buffer = (byte[])dr[45];
    
    MemoryStream strm = new MemoryStream(buffer);
    strm.Write(buffer, 0, buffer.Length);
    strm.Position = 0;
    
    Image img = Image.FromStream(strm);
    pictureBox1.Image = Image.FromStream(strm);//errorinvalid parameter




当我尝试将图像显示到图片框中时,我得到错误无效参数,如上面以粗体显示的内容...
我可以知道如何解决此问题吗?请帮助我..




when i trying to show the image into picture box i m getting the error invalid parameter as write above in bold...
may i know how can i solve this problem...please help me..

推荐答案

可以尝试删除这些行吗?
Can you try removing these lines
strm.Write(buffer, 0, buffer.Length);
strm.Position = 0;


图片img = Image.FromStream(strm);
pictureBox1.Image = Image.FromStream(strm);//错误无效的参数

如果img是图像,则问题在于您已使用流创建图像,那么为什么不将img设置为您的图片框图像呢?此外,为什么所有变量名都是默认名称,因此难以阅读且毫无意义?为什么要在表示层中阅读SQL?这段代码中有很多问题.

另一个人是对的,您的代码已将缓冲区传递进来,不需要再次读取它.您的代码看起来像您在猜测.

只需添加,img = xxx行不会爆炸的事实,告诉我您的流是有效的.如果炸毁了,我会假设您的流无效​​.
Image img = Image.FromStream(strm);
pictureBox1.Image = Image.FromStream(strm);//errorinvalid parameter

If img is an image, then the issue is that you''ve used the stream to create an image, so why are you not setting img to be your picturebox image ? Also, why are all your variable names the default, and therefore hard to read and meaningless ? Why are you reading SQL in the presentation layer ? There''s a lot of issues in this code.

The other guy is right, your code has passed the buffer in, it doesn''t need to read it again. your code looks like you are guessing.

Just to add, the fact that the img = xxx line does not blow up, tells me your stream is valid. If it blew up, I''d assume your stream is not valid.


这篇关于图片img = Image.FromStream(strm); //无效的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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