byte[] read1bitImage(InputStream in) throws IOException { if (fi.compression == FileInfo.LZW) throw new IOException("ImageJ cannot open 1-bit LZW compressed TIFFs"); int scan = (int) Math.ceil(width / 8.0); int len = scan * height; byte[] buffer = new byte[len]; byte[] pixels = new byte[nPixels]; DataInputStream dis = new DataInputStream(in); dis.readFully(buffer); int value1, value2, offset, index; for (int y = 0; y < height; y++) { offset = y * scan; index = y * width; for (int x = 0; x < scan; x++) { value1 = buffer[offset + x] & 0xff; for (int i = 7; i >= 0; i--) { value2 = (value1 & (1 << i)) != 0 ? 255 : 0; if (index < pixels.length) pixels[index++] = (byte) value2; } } } return pixels; }