Added an extension method to clone bitmaps with a 32bbpArgb pixel format.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
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 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<bool> bits)
|
public static int ToBits(this IEnumerable<bool> bits)
|
||||||
{
|
{
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ namespace OpenRA
|
|||||||
if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb)
|
if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb)
|
||||||
{
|
{
|
||||||
var original = CustomPreview;
|
var original = CustomPreview;
|
||||||
CustomPreview = original.Clone(original.Bounds(), PixelFormat.Format32bppArgb);
|
CustomPreview = original.CloneWith32bbpArgbPixelFormat();
|
||||||
original.Dispose();
|
original.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ namespace OpenRA
|
|||||||
if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb)
|
if (CustomPreview.PixelFormat != PixelFormat.Format32bppArgb)
|
||||||
{
|
{
|
||||||
var original = CustomPreview;
|
var original = CustomPreview;
|
||||||
CustomPreview = original.Clone(original.Bounds(), PixelFormat.Format32bppArgb);
|
CustomPreview = original.CloneWith32bbpArgbPixelFormat();
|
||||||
original.Dispose();
|
original.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user