我又遇到了gdi+一般性错误
继上次写得随笔,关于一个gdi+的一般性错误,那个自己找到了原因。但是这个次的虽然那按照别人写得方法解决了,但是尚未明白为什么。
通过PictureBox来保存图像到数据库,成为二进制的文件的时候,
可能你会碰到GDI+一般性错误的消息,具体解决的办法是把他读取道一个新的Bitmap类中,再Save!代码如下!
using(MemoryStream stream = new MemoryStream())
{
byte[] bytearr = new byte[0];
if (this.picImage.Image != null)
{
try
{
Bitmap bmp = new Bitmap(picImage.Image);
bmp.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
bytearr = stream.ToArray();
staff.StaffPhotoImg = bytearr;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
算了,也不管它。就当是picture box的bug