public static Pixmap Bitmapize(Pixmap pixmap, int threshold) { pixmap.GetSize(out int width, out int height); Gdk.Image image = pixmap.GetImage(0, 0, width, height); Pixmap bitmap = new Pixmap(null, width, height, 1); Gdk.GC bitSetter = new Gdk.GC(bitmap) { Function = Gdk.Function.Set }; Gdk.GC bitClearer = new Gdk.GC(bitmap) { Function = Gdk.Function.Clear }; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (BitConverter.GetBytes(image.GetPixel(x, y))[0] >= threshold) { bitmap.DrawPoint(bitSetter, x, y); } else { bitmap.DrawPoint(bitClearer, x, y); } } } return(bitmap); }