类型为' System.ArgumentException'的未处理异常发生在System.Drawing.dll中的附加信息:参数无效

时间:2017-01-17 17:43:08

标签: c# winforms system.drawing system.drawing.imaging

我必须在pictureBox(Winforms应用程序)中显示二进制图像,但有例外"参数无效"。下面是我的代码,我搜索了很多,但找不到所需的解决方案。

        ClsCustomerTransaction ct = new ClsCustomerTransaction();
        byte[] photo_aray = (byte[])ct.GetPicture().Rows[0][0];
        MemoryStream ms = new MemoryStream();
        ms.Write(photo_aray, 0, photo_aray.Length);            
        pictureBox1.Image = Image.FromStream(ms);

图像通过以下代码保存在数据库中。

MemoryStream ms = new MemoryStream();
            byte[] PhotoByte = null;
            pictureBox1.Image.Save(ms, ImageFormat.Png);
            PhotoByte = ms.ToArray();
            ClsDressImages.Specification = txtSpecification.Text;
            ClsDressImages.Img = PhotoByte;
            if (ClsDressImages.SaveImage())
            {
                MessageBox.Show("Successfully saved");
                Reset();
            }

public class ClsDressImages
    {
        public static string table;
        public static string Specification { get; set; }
        public static byte[] Img { get; set; }

        public static bool SaveImage()
        {
            ClsDatabaseManager dbm = ClsDatabaseManager.InitializeDbManager();
            bool result = false;
            try
            {
                dbm.Open();
                result = dbm.ExecuteNonQuery("INSERT INTO " + table + " VALUES (N'" + Specification + "','" + Img + "')", CommandType.Text).ToBool();
                dbm.Dispose();
            }
            catch (Exception ex)
            {
                dbm.Dispose();
                throw ex;
            }
            return result;
        }
    }

提前致谢。

0 个答案:

没有答案