简体   繁体   中英

How to save a Picture to a Picturebox?

Here's the current code I have:

private void BrowsePicture_Click(object sender, EventArgs e) // Browse Picture
    {
        OpenFileDialog OFD = new OpenFileDialog();
        if(OFD.ShowDialog()==DialogResult.OK)
        {
            Bitmap Image = new Bitmap(OFD.FileName);
            ProfilePicture.Image = Image;
            ProfilePicture.SizeMode = PictureBoxSizeMode.Zoom;
        }
    }

I would like to save the image on the PictureBox so that when the software is closed and opened again later, the image will still be in there. Can this can be done through Properties.Settings ?

Where are you saving this data? You should save your setting in a place that you can read when you do the login action and then set the value in your PictureBox .

EDIT:

To save the image in your specific folder:

Bitmap b = new Bitmap("your image location"); b.Save("your folder location + your image name with extension");

To read the image and set into your PictureBox do this in the Load event:

pictureBox1.Image = Image.FromFile("your image location");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM