如何在pictureBox1中实时显示每次图像已保存到硬盘

本文关键字:图像 保存 硬盘 显示 pictureBox1 实时 | 更新日期: 2023-09-27 17:51:02

我有一个新的形式我添加到我的项目:我叫新的形式Images.cs在新的Form构造函数中,我调用了一个名为Test的方法:

public Images()
        {
            InitializeComponent();
            Test();
        }

Test方法:

Bitmap bmp = new Bitmap(@"e:'test.bmp");
Bitmap bmp1 = ImageTrim.ImagesTrim(bmp);
bmp1.Save(@"e:'Image'image" + imagescount.ToString() + ".bmp",                              System.Drawing.Imaging.ImageFormat.Bmp);
bmp1.Dispose();
bmp.Dispose();
filePaths = Directory.GetFiles(@"e:'Image'", "*.bmp");
Bitmap newbmp = new Bitmap(filePaths[0]);
Form1 f1 = new Form1();
f1.bmptoshow = newbmp;
Form1.pb1.Image = newbmp;
Form1 f1 = new Form1();
f1.bmptoshow = newbmp;
newbmp.Dispose();
imagescount++;

变量imagescount是一个全局整型。

变量fileppaths是字符串[],并且我将其设置为全局和公共。

在本例中,filepath包含2个条目。

我想传递第一项bmp图像文件到Form1 pictureBox1,并在Form1 pictureBox1中显示bmp文件。

In form1 what i did:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WebBrowserScreenshots.cs
{
    public partial class Form1 : Form
    {
        public static PictureBox pb1 = new PictureBox();
        public Form1()
        {
            InitializeComponent();
            pictureBox1.Image = pb1.Image;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            WebBrowserScreenshots wbss = new WebBrowserScreenshots();
        }
        public Bitmap bmptoshow
        {
            set
            {
                this.pictureBox1.Image = value;
            }
        }
    }
}

无论是在Form1中使用bmptoshow还是在Form1中使用公共静态,pb1都不会在Form1中的pictureBox1上显示任何内容

如何在pictureBox1中实时显示每次图像已保存到硬盘

那么,一旦保存了图像,您想要在PictureBox中显示该图像吗?在我的脑子里你可以实现这个:

public void imageSaved(){
if(File.exists(//Whatever your file name is, to check it actually saved){
PictureBox1.image = //Image location
}
else{
MessageBox.show("Image didnt save!");
}
}