只运行以上代码没有问题,但如果从SQL数据库取图片数据绑定到c1PictureBox1,如以下代码:
this.c1PictureBox1.DataSource=this.itemVendorReport1.ItemVendorReporting;
this.c1PictureBox1.DataField ="reportImage";
执行this.c1PictureBox1.Image.Save(System.IO.Directory.GetCurrentDirectory()+"\\temp.jpg",System.Drawing.Imaging.ImageFormat.Jpeg); 就会出错。旧版本不会。
现在我改用以下方法处理,问题解决了。非常感谢!
byte[] MyPicter = new byte[0];
MyPicter = (byte[])this.itemVendorReport1.ItemVendorReporting.Rows[0]["reportImage"];
int ArraySize = MyPicter.GetUpperBound(0);
FileStream fs = new FileStream(System.IO.Directory.GetCurrentDirectory() + "\\temp.jpg", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyPicter, 0, ArraySize);
fs.Close();
if (System.IO.File.Exists(System.IO.Directory.GetCurrentDirectory() + "\\temp.jpg"))
{
System.Diagnostics.Process.Start(System.IO.Directory.GetCurrentDirectory() + @"\temp.jpg");
}
else
{
MessageBox.Show("无测试报告!", "查无报告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} |