我难以阅读2008年服务器数据库的图像,并将其装在Windows表格PictureBox
。 这是从亚洲开发银行检索图像的法典:
//UI Button Binded Code
private void LoadImage_Click(object sender, RoutedEventArgs e)
{
DataSet data = DBClient.GetEmployee(_EID[0]);
//...
//...
byte[] pic = (byte[])data.Tables[0].Rows[0]["Picture"];
EmployeeCardForm ef = new EmployeeCardForm(name, fname, nic, deptt, desig, doj, address, ecode, pic);
ef.Show();
}
//EmployeeCardForm Constructor File Code
public EmployeeCardForm(String name, String fname, String nic, String deptt, String desig, String doj, String address, String ecode, byte[] pic)
{
InitializeComponent();
this.MaximizeBox = false;
label18.Text = "Record has been successfully Saved. Please take Print out by pressing Print Button below!";
try
{
pictureBox1.Image = Image.FromStream(new MemoryStream(pic));
//Some code here
}
catch (IOException e)
{
MessageBox.Show("Some Error occurred!");
}
//declare event handler for printing in constructor
printdoc1.PrintPage += new PrintPageEventHandler(printdoc1_PrintPage);
}
当我管理这一方案并点击纽子装上图像时,申请便没有反应。 我在总结后获悉,以下法典有问题:
pictureBox1.Image = Image.FromStream(new MemoryStream(pic));
And when I used try/catch block, it showed me following exception:
System.ArgumentException: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.Image.FromStream(Stream stream) at SimpleReport.EmployeeCardForm..ctor(String name, String fname, String nic, String deptt, String desig, String doj, String address, String ecode, Byte[] pic) in D:O ProjectsEMSimpleReportEmployeeCardForm.cs:line 60
This is how i am saving image into DB:
private void SaveImage_Click(object sender, RoutedEventArgs e)
{
Picture_Path= filename;
FileStream fs;
fs = new FileStream(@Picture_Path, FileMode.Open, FileAccess.Read);
//a byte array to read the image
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
DBClient.AddEmployee(ecode, emp_name.Text, fname, nic, deptt, desig, doj, address, picbyte);
}