Is there a ready class for converting an integer array into a bitmap and back? Specifically interested in byte -> bit. Did so

_IS = new byte[corSize]; for (int y = 0, k = 0; y < _Image.Height; y++) for (int x = 0; x < _Image.Width; x++) for (int i = 0, _Mask=128; i < 8; i++,k++,_Mask>>=1) _IS[k] = (byte)((_Image.GetPixel(x, y).R & _Mask) >> (7 - i)); 

But it is very slow.

  • And where is the resulting bitmap? And the original integer is not visible. - PinkTux
  • _IS is a bitmap where I write the bits, _Image is the drawing from which I get the R-component of each pixel. - Dart Lightec
  • _IS is a byte array. - PinkTux
  • I represent an array of bits in a byte array; 1 | 0 is written to the byte element - Dart Lightec
  • Hence, the formulation of the problem is incorrect. - PinkTux

1 answer 1

byte -> bit

It is not entirely clear how the example relates to the conditions of the problem. But if to distract from it, then:

 import java.util.BitSet; byte[] bytes = new byte[] { (byte) 0x7F }; BitSet bits = BitSet.valueOf(bytes); System.out.println("Bits length: " + bits.length()); for (int i = 0; i < bits.length(); i++) { System.out.println("bit " + i + ": " + bits.get(i)); } 
  • That is necessary, thank you. - Dart Lightec