diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index b5e3a6c9de..6acf22c314 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Imaging; using System.Globalization; using System.Linq; using System.Reflection; @@ -434,6 +435,25 @@ namespace OpenRA public static Rectangle Bounds(this Bitmap b) { return new Rectangle(0, 0, b.Width, b.Height); } + public static Bitmap CloneWith32bbpArgbPixelFormat(this Bitmap original) + { + // Note: We would use original.Clone(original.Bounds(), PixelFormat.Format32bppArgb) + // but this doesn't work on mono. + var clone = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb); + try + { + using (var g = System.Drawing.Graphics.FromImage(clone)) + g.DrawImage(original, original.Bounds()); + } + catch (Exception) + { + clone.Dispose(); + throw; + } + + return clone; + } + public static int ToBits(this IEnumerable bits) { var i = 0; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index b61ed70706..ffbcf494ba 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -398,7 +398,7 @@ namespace OpenRA if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb) { var original = CustomPreview; - CustomPreview = original.Clone(original.Bounds(), PixelFormat.Format32bppArgb); + CustomPreview = original.CloneWith32bbpArgbPixelFormat(); original.Dispose(); } } diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index ab3bbd3402..2b85004f38 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -159,7 +159,7 @@ namespace OpenRA if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb) { var original = CustomPreview; - CustomPreview = original.Clone(original.Bounds(), PixelFormat.Format32bppArgb); + CustomPreview = original.CloneWith32bbpArgbPixelFormat(); original.Dispose(); } }