English 中文(简体)
图像从2008年服务器到图像Box故障[闭门]
原标题:Image Load from SQL Server 2008 to PictureBox fails [closed]

我难以阅读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);
}

问题回答

在一些聊天之后,问题在于,图像二元储存在数据库中格式不正确。 可能有几个问题:

  1. Incorrect type/size of table field.
  2. Incorrect byte reading

如有<代码> 千字节(最大)数据表领域类型,则进行第一次核对。

第二,这里是你如何阅读所有档案:

private void SaveImage_Click(object sender, RoutedEventArgs e)
{
    byte[] allFileBytes = File.ReadAllBytes(filename); 
    DBClient.AddEmployee(ecode, emp_name.Text, fname, nic, deptt, desig, doj, address, allFileBytes);
}




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签