troubleshooting Question

Draw PNG files from EMF files faster

Avatar of ericvbnet
ericvbnet asked on
.NET ProgrammingVisual Basic.NET
20 Comments1 Solution936 ViewsLast Modified:
Hello Experts, I use the code below to convert my EMF files to PNG files for many graphs at a time. Two of the steps are very slow: memoryGraphics.DrawImage and memoryBitmap.Save

I am asking for suggestions on how to speed these two steps up considerably, or an alternative faster way to generate the .png files from the EMF files.

'NewImage is the path to my EMF file        
Dim imgMeta As New Metafile(NewImage)
Dim myWidth As Integer
Dim myHeight As Integer
myWidth = imgMeta.Width
myHeight = imgMeta.Height
'  We want a high quality .png file.
'  Let's quadruple the height and width.
myWidth = myWidth * 4
myHeight = myHeight * 4
Dim memoryBitmap As Bitmap
memoryBitmap = New Bitmap(myWidth, myHeight) 'adds 4 seconds for 107 graphs (14 seconds to 18 seconds)
Dim memoryGraphics As Graphics
memoryGraphics = Graphics.FromImage(memoryBitmap)
' Draw the Metafile to memory
memoryGraphics.DrawImage(imgMeta, 0, 0, myWidth, myHeight) 'adds 20 seconds for 107 graphs (18 to 38)
memoryBitmap.Save(GloTempPath & "\pngversion.png", ImageFormat.Png) 'add 30 more seconds (38 to 68) 68 is total time
Get vaccinated; Social distance; Wear a mask
Join our community to see this answer!
Unlock 1 Answer and 20 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros