0
当我把这种方法它显示错误:无效的参数,请帮助我得到错误:无效的参数时,我从OLEDB数据库retrive图像
public void DisplayDoc()
{
try
{
con = new OleDbConnection(constr);
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd = new OleDbCommand("Select pic from doc where adharno= '" + this.aadhar + "'", con);
OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
DataRow row = dt.Rows[0];
pictureEmployeePhoto.Image = LoadPhoto((byte[])row["pic"]);
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error :" + ex.Message);
}
}
private Image LoadPhoto(byte[] photo)
{
MemoryStream ms = new MemoryStream(photo);
return Image.FromStream(ms); //Getting Error Here: Invalid Parameter
}
下面的方法我都用过以将图像存储在数据库中
byte[] Pic;
OpenFileDialog ofdPhoto;
MemoryStream ms = new MemoryStream();
private void btnPhotoUpload_Click(object sender, EventArgs e)
{
// open file dialog
ofdPhoto = new OpenFileDialog();
// image filters
ofdPhoto.Title = "Select Employee Photo";
ofdPhoto.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
ofdPhoto.FileName = null;
if (ofdPhoto.ShowDialog() == DialogResult.OK)
{
// display image in picture box
pictureEmployeePhoto.Image = new Bitmap(ofdPhoto.FileName);
// image file path
txtPhotoFilePath.Text = ofdPhoto.FileName;
try
{
// Here get_image is a function and Big is the byte[] type
Pic = get_image();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex.Message.ToString());
}
}
}
public byte[] get_image()
{
MemoryStream ms = new MemoryStream();
pictureEmployeePhoto.Image.Save(ms,pictureEmployeePhoto.Image.RawFormat);
return ms.GetBuffer();
}
哪一行代码给你错误? –
return Image.FromStream(ms); //错误在这里:无效参数 – ehh
是Chetan Ranpariya –