Argumentexception是未处理的参数在C#中无效 [英] Argumentexception was unhandled parameter not valid in C#

查看:94
本文介绍了Argumentexception是未处理的参数在C#中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我在postgres数据库中保存了一张图片。



当我想要在图片框中检索图像我收到此错误ArgumentException未处理参数无效。我已经粘贴了我的编码。



我尝试了什么:



我已经尝试过互联网上的各种解决方案,但我无法解决这个问题。

请告诉我哪里出错了。

Hi friends,

I have saved an image in my postgres database.

when i want to retrieve the image back in the picture box i am getting this error ArgumentException was unhandled Parameter not valid. i have pasted my codings.

What I have tried:

I have tried all sorts of solutions from internet but i could not solve this.
Please tell me where i have gone wrong.

public Image byteArrayToImage(byte[] byteArrayIn)
{
    MemoryStream ms = new MemoryStream(byteArrayIn); 
    Image returnImage = Image.FromStream(ms);
    return returnImage;

}

byte[] photo = System.Text.Encoding.Unicode.GetBytes(dr2["customerimage"].ToString());
pictureBox2.Image = byteArrayToImage(photo);

推荐答案

简单:这可能是你如何保存它导致问题:为什么我会得到一个参数无效。我从数据库中读取图像时出现异常? [ ^ ]
Simple: it's probably how you saved it that is causing the problem: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]


这样的事情:

Something like this:
command = new NpgsqlCommand("select customerimage from mytable where id = 1);", conn);
Byte[] result = (Byte[])command.ExecuteScalar();

FileStream fs = new FileStream("database", FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(new BufferedStream(fs));

bw.Write(result);
bw.Flush();
fs.Close();
bw.Close();


这篇关于Argumentexception是未处理的参数在C#中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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