I have a problem when saving slides to images using SaveAsImage with .Net Core under Linux.
Saving single slides works fine, but when I try to save all slides to images in a loop:
- Code: Select all
For Each slide As ISlide In c_PresentationDocument.Slides
' Export thumbnails
Console.WriteLine("Generating thumbnail for slide " & i & "/" & c_PresentationDocument.Slides.Count)
strNumber = i.ToString
' Insert leading zeros
While strNumber.Length < c_PresentationDocument.Slides.Count.ToString.Length
strNumber = "0" & strNumber
End While
' Export thumbnail
sImageName = filename & "_Slide" & strNumber & ".jpg"
img = slide.SaveAsImage()
img.Save(glb.strPathTarget & sImageName, System.Drawing.Imaging.ImageFormat.Jpeg)
i = i + 1
Next ' slide
I get the following error:
Unhandled exception. System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.SafeNativeMethods.Gdip.CheckStatus(Int32 status)
at System.Drawing.Graphics.Dispose()
at System.Drawing.Graphics.Finalize()
When I run the program under Windows, it works flawlessly. The error only occurs when run under Linux (Ubuntu 20.04).
Stepwise debugging shows that the exception occurs upon slide.SaveAsImage()
Can you imagine what is happening here, and how to get around it?
Kind Thanks.