static Image2B iBinaryImageToImage2B(IBinaryImage img) { if (img == null) null; if (img cast Image2B) ret img; int w = img.getWidth(), h = img.getHeight(); byte[] pixels = new[(w*h+7)/8]; int i = 0; for y to h: for x to w: { if (img.getBoolPixel(x, y)) pixels[i/8] |= 1 << (i & 7); i++; } ret new Image2B(w, h, pixels); }