I had a similar problem and was able to fix it by making a change in the constructor of XImage
Current code
Code:
this.wpfImage = new BitmapImage(new Uri(path)); // AGHACK
Replacement code
Code:
BitmapImage temp;
temp = new BitmapImage();
temp.BeginInit();
temp.CacheOption = BitmapCacheOption.OnLoad;
temp.UriSource = new Uri(path);
temp.EndInit();
this.wpfImage = temp;
I found this fix for BitmapImage on stackoverflow (
http://stackoverflow.com/questions/6430 ... -lock-file)
Also, I'm not sure if this is a belt and suspenders type thing, but when I create an XImage I do it in a using block
Code:
Using image As XImage = XImage.FromFile("C:\temp\locked_image.jpg")
imageHeight = pageWidth / image.PixelWidth * image.PixelHeight
gfx.DrawImage(image, marginLeft, marginTop, pageWidth, imageHeight)
End Using