图片转成byte数组
winform中PictureBox 中的
用方法System.Drawing.Image.Save 报错误
A generic error occurred in GDI+.
解决办法
private byte[] ImageToByte(PictureBox pb)
{
//Image image =(Image) pb.Image.Clone();
Image image =pb.Image;
// pb.Image.Dispose();
byte[] b = null;
try
{
Image sceneImage = new Bitmap(image);
////实例化流
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
//将图片的实例保存到流中
sceneImage.Save(imageStream, ImageFormat.Png);
//保存流的二进制数组
byte[] imageContent = new Byte[imageStream.Length];
imageStream.Position = 0;
//将流泻如数组中
imageStream.Read(imageContent, 0, (int)imageStream.Length);
return imageStream.ToArray();
}
catch (Exception ex)
{
throw;
}
// return b;
}