Skip to content

Commit 7d6dbc2

Browse files
committed
[DW-34] add dynamic treshold (.net6+)
1 parent 3653403 commit 7d6dbc2

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

  • IronSoftware.Drawing/IronSoftware.Drawing.Common

IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,7 +3040,25 @@ object ICloneable.Clone()
30403040
/// <returns></returns>
30413041
private static IImageEncoder GetDefaultImageImportEncoder(int imageWidth, int imageHeight)
30423042
{
3043-
const int threshold = 1920 * 1080;
3043+
3044+
int threshold = 1920 * 1080; //FHD
3045+
#if NET6_0_OR_GREATER
3046+
long totalBytes = GC.GetGCMemoryInfo().TotalAvailableMemoryBytes;
3047+
long totalGB = totalBytes / (1024L * 1024 * 1024);
3048+
3049+
if (totalGB <= 2)
3050+
threshold = 1280 * 720; //HD
3051+
else if (totalGB <= 4)
3052+
threshold = 1920 * 1080; //FHD
3053+
else if (totalGB <= 8)
3054+
threshold = 2560 * 1440; //2K
3055+
else if (totalGB <= 16)
3056+
threshold = 4096 * 2160; //4K
3057+
else if (totalGB <= 32)
3058+
threshold = 7680 * 4320; //8K
3059+
else if (totalGB <= 64)
3060+
threshold = 15360 * 8640; //16K
3061+
#endif
30443062
if (imageWidth * imageHeight <= threshold)
30453063
{
30463064
//small Image
@@ -3181,7 +3199,7 @@ private static void InternalSaveAsMultiPageGif(IEnumerable<Image> images, Stream
31813199
}
31823200
}
31833201

3184-
#endregion
3202+
#endregion
31853203

31863204
[Browsable(false)]
31873205
[Bindable(false)]

0 commit comments

Comments
 (0)