public IMask CreateMask(IGameFactory factory, string path, bool transparentMeansMasked = false, Color?debugDrawColor = default(Color?), string saveMaskToFile = null, string id = null) { FastBitmap debugMaskFast = null; if (saveMaskToFile != null || debugDrawColor != null) { debugMaskFast = new FastBitmap(Width, Height); } bool[][] mask = new bool[Width][]; Color drawColor = debugDrawColor != null ? debugDrawColor.Value : Colors.Black; using (FastBitmap bitmapData = new FastBitmap(_cgImage)) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { bool masked = bitmapData.IsOpaque(x, y); if (transparentMeansMasked) { masked = !masked; } if (mask[x] == null) { mask[x] = new bool[Height]; } mask[x][Height - y - 1] = masked; if (debugMaskFast != null) { debugMaskFast.SetPixel(x, y, masked ? drawColor : Colors.Transparent); } } } } UIImage debugMask = null; if (debugMaskFast != null) { debugMask = debugMaskFast.GetImage(); debugMaskFast.Dispose(); } //Save the duplicate if (saveMaskToFile != null) { saveToFile(debugMask, saveMaskToFile); } IObject debugDraw = null; if (debugDrawColor != null) { debugDraw = factory.Object.GetObject(id ?? path ?? "Mask Drawable"); debugDraw.Image = factory.Graphics.LoadImage(new IOSBitmap(debugMask, _graphics), null, path); debugDraw.Anchor = new AGS.API.PointF(); } else if (debugMask != null) { debugMask.Dispose(); } return(new AGSMask(mask, debugDraw)); }