Quote Originally Posted by paulg4ije View Post
I don't want to take this off at a tangent but I thought the usual error message when an image file was locked was something like "A generic error occurred in GDI+" - unless this has changed in later versions of VS. I wonder if the use of Onedrive here is significant?

This is my method of opening an image so the file is not locked:
Code:
' Open new image using FileStream so file is not locked
Using fs As FileStream = New FileStream(filename, FileMode.Open)
    Dim bm As Bitmap = CType(Image.FromStream(fs), Bitmap)
    PictureBox1.Image = bm
End Using
The pattern is becoming clear. Our 'methods' are really similar to Passel's:

1. Get the image from a file (Passel's b1, your FileStream, my Image.FromFile).
2. Copy the image from step 1 (Passel's b2, your Image.FromStream, my New Bitmap(image)
3. Dispose of the first image (b1.Dispose, End Using, my img.Dispose). This breaks the link with the file.

Actually, I normally prefer Using..End Using blocks to Dispose statements, because they emphasize the temporary lifespan of the object.

As for the error messages in System.Drawing, it wouldn't surprise me if they have upgraded the messages in later Framework versions. From useless garbage to unhelpful gibberish.

BB