diff --git a/ClosedXML/ClosedXML/ClosedXML/Utils/GraphicsUtils.cs b/ClosedXML/ClosedXML/ClosedXML/Utils/GraphicsUtils.cs index 954c22c..b5e6762 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Utils/GraphicsUtils.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Utils/GraphicsUtils.cs @@ -5,17 +5,24 @@ { internal static class GraphicsUtils { + [ThreadStatic] + private static Graphics threadLocalGraphics; + private static Graphics g + { + get + { + if (threadLocalGraphics == null) + { + var image = new Bitmap(1, 1); + threadLocalGraphics = Graphics.FromImage(image); + } + return threadLocalGraphics; + } + } + public static SizeF MeasureString(string s, Font font) { - SizeF result; - using (var image = new Bitmap(1, 1)) - { - using (var g = Graphics.FromImage(image)) - { - result = g.MeasureString(s, font, Int32.MaxValue, StringFormat.GenericTypographic); - } - } - + SizeF result = g.MeasureString(s, font, Int32.MaxValue, StringFormat.GenericTypographic); return result; } }