diff --git a/src/Microsoft.ML.ImageAnalytics/ImageLoader.cs b/src/Microsoft.ML.ImageAnalytics/ImageLoader.cs index 07ecbb37be..a8120cd524 100644 --- a/src/Microsoft.ML.ImageAnalytics/ImageLoader.cs +++ b/src/Microsoft.ML.ImageAnalytics/ImageLoader.cs @@ -237,7 +237,11 @@ private Delegate MakeGetterImageDataViewType(DataViewRow input, int iinfo, Func< if (!string.IsNullOrWhiteSpace(_parent.ImageFolder)) path = Path.Combine(_parent.ImageFolder, path); - dst = new Bitmap(path) { Tag = path }; + // to avoid locking file, use the construct below to load bitmap + var bytes = File.ReadAllBytes(path); + var ms = new MemoryStream(bytes); + dst = (Bitmap)Image.FromStream(ms); + dst.Tag = path; // Check for an incorrect pixel format which indicates the loading failed if (dst.PixelFormat == System.Drawing.Imaging.PixelFormat.DontCare)