I am working on a mechanism that will allow me to get a two-dimensional array filled with binary data based on constBits() from QImage created with flag QImage::FormatMono.
I expect that square should be something like:
1111
1001
1001
1111
but i get this instead:
0001
0010
0100
1000
I am not quite imagine how to work with memory bit by bit or how to work with MSB-compressed string.
Here is the code that I use to get value of 1 pixel and represent it as binary:
uint ConnectedChecker::pixel(const QImage& img, const int x, const int y) const
{
const uchar mask = 0x80 >> (x % 8);
return img.constBits()[x*y / 8] & mask ? 1 : 0;
}
And loop, that i use to fill the array:
int* _in;
for(uint i = 0; i < _rowCount; ++i) {
for(uint j = 0; j < _columnCount; ++j) {
*((_in + i*_columnCount) + j) = pixel(image, i, j);
}
}