Answer the question
In order to leave comments, you need to log in
How to get its binary representation from a QByteArray element?
Good afternoon.
I have a QByteArray of an image received over the serial port. Each element of QByteArray is 1 pixel (8 bits), color from 0 to 255. I need to form 8 pictures from this base image. The generation algorithm is as follows:
Take the least significant (zero, right) bit of the first pixel of the source image, if it is 0 , then the first byte (pixel) of the first generated image must be black ( '00000000' , '0x00' , 0 ), if the least significant bit of the first pixel of the source image is 1 , then the first byte(pixel) of the first generated image must be white( '11111111' ,'0xFF' , 255 ). We also act with the first bit of the first pixel of the original image, but we form the first pixel of the second image, and so on for the first pixels of all the remaining ones. The operation is repeated for all pixels of the original image, thereby forming 8 two-color images.
Using Python 2.7 , I implemented the algorithm like this:
def run(self):
self.start_gen.emit(len(self.source_img))
pb_val = 0
for img in self.nine:
self.nine[img] = bytearray(b'')
for byte_ in self.source_img:
pb_val += 1
self.generating.emit(pb_val)
bit_str = by2bi(byte_)
for i in range(8):
if bit_str[i] == '0':
self.nine['img_' + str(i)] += self.b0
else:
self.nine['img_' + str(i)] += self.b255
self.stop_gen.emit()
QVector<QByteArray> generated_images;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question