I clone it into another bitmap, then set the original to Nothing
- TempImage.Dispose() 'tried it with and without this
-
TempImage = Nothing
-
You try to dispose of it, then try to give the disposed of object a value? Garbage Collection cannot take place on an object this is still in scope and has a value.
Worst case scenario, you might want to stop reading the graphic like that and use a file stream instead. You are welcome to translate my C# code that does this.
- Image TempImage = null;
-
Image FinalImage = null;
-
bool Success = false;
-
-
if (ImagePath.StartsWith(".")) return FinalImage;
-
-
#region Load the image from file
-
if (File.Exists(ImagePath))
-
{
-
DateTime FailAt = DateTime.Now.AddSeconds(30);
-
while (TempImage == null)
-
{
-
if (DateTime.Now > FailAt) break; // Don't wait forever if the file is junk
-
FileStream fs = null;
-
try
-
{
-
fs = new FileStream(ImagePath, FileMode.Open, FileAccess.Read);
-
TempImage = Image.FromStream(fs, false);
-
Success = true;
-
}
-
catch
-
{
-
}
-
}
-
}
-
This also incorporates multiple attempts to read the file, until a time-out occurs.
Just because windows shows the file, doesn't mean its done writing. Copying and saving can take time.