[英]Saving image from “pictureBox1” to a file with a click on a button in C#
I found this code on here, and I want to save the image I get in my "pictureBox1" with a button like under, how can I implement these together? 我在这里找到了这段代码,我想用下面的按钮保存在“ pictureBox1”中得到的图像,如何将它们一起实现? I have the picture showing in the pictureBox1, I want to click a button and be able to store the picture on my PC.
我的图片显示在pictureBox1中,我想单击一个按钮并能够将图片存储在我的PC上。
private void button1_Click(object sender, EventArgs e)
This is the code to save image: 这是保存图像的代码:
public static void SaveImageCapture(System.Drawing.Image image)
SaveFileDialog s = new SaveFileDialog();
s.FileName = "Image";// Default file name
s.DefaultExt = ".Jpg";// Default file extension
s.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension
s.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
s.RestoreDirectory = true;
if (s.ShowDialog() == DialogResult.OK)
{
// Save Image
string filename = s.FileName;
(System.IO.FileStream fstream = new System.IO.FileStream(filename, System.IO.FileMode.Create))
{
image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
fstream.Close();
I am also not 100% sure i understand what you mean. 我也不是100%肯定我理解您的意思。 but here is a 2 lines of codes, showing the simplest way of loading and saving an image into a picturebox.
但是这里有两行代码,显示了将图片加载和保存到图片框的最简单方法。
// 1. Load a picture into the picturebox
PictureBox pic = new PictureBox() { Image = Image.FromFile("SomeFile.jpg") };
// 2. Save it to a file again
pic.Image.Save("SomeFilePath.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
I fixed it by doing this: 我通过执行此操作来修复它:
private void btnSave_Click(object sender, EventArgs e)
{
pictureBox1.Image.Save(@"C:\Temp\test.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.