File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
System.Drawing.Common/src/System/Drawing/Imaging
System.Private.Windows.Core/src/Windows/Win32/Graphics/GdiPlus Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,8 @@ public static ImageCodecInfo[] GetImageDecoders()
57
57
58
58
public static ImageCodecInfo [ ] GetImageEncoders ( )
59
59
{
60
+ GdiPlusInitialization . EnsureInitialized ( ) ;
61
+
60
62
ImageCodecInfo [ ] imageCodecs ;
61
63
uint numEncoders ;
62
64
uint size ;
Original file line number Diff line number Diff line change 3
3
4
4
namespace Windows . Win32 . Graphics . GdiPlus ;
5
5
6
+ /// <summary>
7
+ /// Helper to ensure GDI+ is initialized before making calls.
8
+ /// </summary>
6
9
internal static partial class GdiPlusInitialization
7
10
{
8
11
private static readonly nuint s_initToken = Init ( ) ;
@@ -23,5 +26,18 @@ private static unsafe nuint Init()
23
26
/// <summary>
24
27
/// Returns true if GDI+ has been started.
25
28
/// </summary>
29
+ /// <remarks>
30
+ /// <para>
31
+ /// This should be called anywhere you make <see cref="PInvokeCore"/> calls to GDI+ where you don't
32
+ /// already have a GDI+ handle. In System.Drawing.Common, this is done in the PInvoke static constructor
33
+ /// so it is not necessary for methods defined there.
34
+ /// </para>
35
+ /// <para>
36
+ /// We don't do this implicitly in the Core assembly to avoid unnecessary loading of GDI+.
37
+ /// </para>
38
+ /// <para>
39
+ /// https://github.com/microsoft/CsWin32/issues/1308 tracks a proposal to make this more automatic.
40
+ /// </para>
41
+ /// </remarks>
26
42
internal static bool EnsureInitialized ( ) => s_initToken != 0 ;
27
43
}
You can’t perform that action at this time.
0 commit comments