#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    How do I overwrite a picture file


    Hi everyone,
    I have a paint program project and I have a problem with overwriting a file already loaded in.

    When I create a new picture and save it as a new file there is no problem to overwrite it.
    But if I first load a saved picture to my picturebox and manipulate it I can't save with the same name.

    How do I solve this problem?

    thanks in advance!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2016
    Posts
    6
    Rep Power
    0
    Hey,I am sharing a code,try this:
    -Make sure to remove your image if that already exists.

    Code:
    private void saveImage()
        {
            Bitmap bmp1 = new Bitmap(pictureBox.Image);
    
           if(System.IO.File.Exists("c:\\t.jpg"))
                  System.IO.File.Delete("c:\\t.jpg");
    
            bmp1.Save("c:\\t.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            // Dispose of the image files.
            bmp1.Dispose();
        }

IMN logo majestic logo threadwatch logo seochat tools logo