am missing something obvious and was hoping someone could enlighten me ... i create a BufferedImage and i access the byte[] via ((DataBufferByte)inBuffImg.getRaster().getDataBuffer()).getData();
BufferedImage bimage = new BufferedImage(10,10,BufferedImage.TYPE_BYTE_GRAY);
gives me a byte[].length of 100 and i can access each individual pixel's gray value with & 0xFF
BufferedImage bimage = new BufferedImage(10,10,BufferedImage.TYPE_4BYTE_ABGR);
gives me a byte[].length of 400 and i can access each individual pixel's a b g and r values with & 0xFF ... all good so far ...
PROBLEM:
BufferedImage bimage = new BufferedImage(10,10,BufferedImage.TYPE_BYTE_BINARY);
gives me a byte[].length of 20 and i can't figure out how to access each individual pixel's 0,1 values from the byte array? (I know how to do this via getRGB() but this is too slow for my use here). any help greatly appreciated. thanks robert
update:
oh ... looks like padding causing the mismatch?
BufferedImage bimage = new BufferedImage(8,10,BufferedImage.TYPE_BYTE_BINARY);
gives byte[].length 10
that makes sense ... each pixel is now exactly a bit without padding because the width of the image is divisible by 8
BufferedImage bimage = new BufferedImage(9,10,BufferedImage.TYPE_BYTE_BINARY);
gives byte[].length 20
all the way up to
BufferedImage bimage = new BufferedImage(16,10,BufferedImage.TYPE_BYTE_BINARY);
gives byte[].length 20
i assume each new row of pixels starts with a bit at bit zero. and end of each line padded to complete 8 bit boundary.