private static Bitmap ChromaKeyIfNecessary(Bitmap bmp, bool treatAsIndexed)
{
if (treatAsIndexed || (bmp.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
{
if (treatAsIndexed)
Log.v("treatAsIndexed=true");
Log.v("Got an indexed bitmap. Doing chroma-keying with zelda-pink chroma. (225,0,126)");
Bitmap bmpNew = ConvertTo32bppBitmap(bmp);
bmp.Dispose();
bmp = bmpNew;
ChromaKey32bppBitmap(bmp, Color.FromArgb(225, 0, 126));
return bmp;
}
// If 24bpp, chroma-key based on pixel at coords (0,0) (top-left)
if (!((bmp.PixelFormat & PixelFormat.Alpha) == PixelFormat.Alpha))
{
DateTime dtConvStart = DateTime.Now;
// ah. chroma-keying time! what fun.
Bitmap bmpNew = ConvertTo32bppBitmap(bmp);
bmp.Dispose();
bmp = bmpNew;
ChromaKey32bppBitmap(bmp, bmp.GetPixel(0, 0));
DateTime dtConvEnd = DateTime.Now;
Log.i("Bitmap chroma-keying of bitmap of size " + bmp.Size.ToString()
+ " took " + (dtConvEnd - dtConvStart).TotalMilliseconds.ToString()
+ "ms.");
}
return bmp;
}