Added an extension method to clone bitmaps with a 32bbpArgb pixel format.

This commit is contained in:
RoosterDragon
2015-04-11 21:05:46 +01:00
parent c1787a8368
commit 84dffce7c1
3 changed files with 22 additions and 2 deletions

View File

@@ -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<bool> bits)
{
var i = 0;