Make System.Drawing code compatible with .NET Core (#4548)