如何保存PictureBox.Image到文件? [英] How to save PictureBox.Image to file?

查看:501
本文介绍了如何保存PictureBox.Image到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面写jpgImage到PictureBox.Image。

  VAR jpgImage =新的字节[jpgImageSize]
...
pictureBox.Image =新位图(新的MemoryStream(jpgImage));

和我可以使用下面的字节数组写入文件

 使用(VAR体重=
    新的BinaryWriter(File.Open(文件名,FileMode.Create,
        FileAccess.Write,FileShare.None)))
{
    bw.Write(jpgImage);
}

但我怎样才能从PictureBox.Image的jpgImage字节数组,所以我可以把它写入该文件?
IOW:?我怎​​么扭转以下从PictureBox.Image得到字节数组

  pictureBox.Image =新位图(新的MemoryStream(jpgImage));


解决方案

试试这个

  pictureBox.Image.Save(@路径,ImageFormat.Jpeg);

I use the following to write jpgImage to a PictureBox.Image.

var jpgImage = new Byte[jpgImageSize];
...
pictureBox.Image = new Bitmap(new MemoryStream(jpgImage));

and I can use the following to write a byte array to a file

using (var bw =
    new BinaryWriter(File.Open(filename, FileMode.Create,
        FileAccess.Write, FileShare.None)))
{
    bw.Write(jpgImage);
}

but how can I get the jpgImage byte array from the PictureBox.Image so I can write it to the file? IOW: how do I reverse the following to get the byte array from the PictureBox.Image?

pictureBox.Image = new Bitmap(new MemoryStream(jpgImage));

解决方案

Try this

pictureBox.Image.Save(@"Path",ImageFormat.Jpeg);

这篇关于如何保存PictureBox.Image到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆