private static Bitmap ConvertTo32bppBitmap(Bitmap bmp)
{
Bitmap newBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb);
BitmapData bdRead = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData bdWrite = newBmp.LockBits(new Rectangle(Point.Empty, bmp.Size),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
// Temporary buffer ugh
byte[] xbuf = new byte[bdRead.Stride * bdRead.Height];
Marshal.Copy(bdRead.Scan0, xbuf, 0, bdRead.Stride * bdRead.Height);
Marshal.Copy(xbuf, 0, bdWrite.Scan0, bdRead.Stride * bdRead.Height);
bmp.UnlockBits(bdRead);
newBmp.UnlockBits(bdWrite);
return newBmp;
}