如何将PictureBox.Image保存到文件?
我使用以下内容将jpgImage写入PictureBox.Image。
var jpgImage = new Byte[jpgImageSize]; ... pictureBox.Image = new Bitmap(new MemoryStream(jpgImage));
我可以使用以下内容将字节数组写入文件
using (var bw = new BinaryWriter(File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.None))) { bw.Write(jpgImage); }
但是如何从PictureBox.Image中获取jpgImage字节数组,以便将其写入文件? IOW:如何反转以下内容以从PictureBox.Image获取字节数组?
pictureBox.Image = new Bitmap(new MemoryStream(jpgImage));
试试这个
pictureBox.Image.Save(@"Path",ImageFormat.Jpeg);
你可以用,
pictureBox.Image.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
例:
System.IO.MemoryStream ms = new System.IO.MemoryStream(); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] ar = new byte[ms.Length]; ms.Write(ar, 0, ar.Length);