Answer the question
In order to leave comments, you need to log in
How to create image from uint8_t array?
Hello, I want to create an image from a uint8_t array.
I'm trying to create an image in .bmp format, the file is created but the result is not the same.
this is the correct image, which I converted via the image2cpp service to a uint8_t array.
Now through this array I want to make an image in .bmp format;
here is the code for the whole
array uint8_t *image = new uint8_t[] {
0x1f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0x7f, 0xfc, 0x7f, 0xff, 0x7f, 0xfe, 0xff, 0x7f, 0x7f, 0xff,
0xff, 0x7f, 0x7f 0xff 0xff 0x7f 0x7f 0xff 0xff 0x7f 0x7f 0xff 0xff 0x7f 0x7f 0xff
0xc0 0x01 0x40 0x03 0xff 0x7f 0x7f 0x7fff 0x7fff 0x7f 0xff, 0xff, 0x7f, 0x7f, 0xff,
0xff 0x7f 0x7f 0xff 0xff 0x7f 0x7f 0xff 0xff 0xff 0x7f 0xff 0x80 0x00 0x00 0x01
0xff 0xff 0x7f 0xff 0xdf 0xfd 0x7f 0xfb 0x7f 0xff 0xf7 0xf7 0x7f 0xff 0xfb 0xef 0x7f 0xff
0xfd 0xdf 0x7f 0xff 0xfe 0xbf 0x40 0x03 0xff
0x3f 0x40 0x03 0xfe 0xdf 0x7f 0xff 0xfd 0xef 0x7f 0xff 0xfb 0xf7 0x7f 0xff 0xf7 0xfb 0x7f
0xff 0x6f 0xfd 0x7f 0x7f0 0xfc, 0x1f, 0xff, 0xff, 0xf8
};
I'm trying to do the following through Qt:
QImage *img = new QImage(image, 32, 32, QImage::Format_Grayscale8);
image->save("out.bmp");
the file is created, the image is black and white, but the glitch effect is not pleasing to the eye
What am I doing wrong? Give advice on how to achieve the original image in .bmp format from an array.
Answer the question
In order to leave comments, you need to log in
Solution to my problem:
QImage img(QImage(bitmap, width, height, (width + 7) / 8, QImage::Format_Mono));
// display img on the form if anyone is interested:
QWidget window;
QLabel label(&window);
QPixmap image_pix(QPixmap::fromImage(image));
label.setPixmap(image_pix);
image_pix.save("out.bmp");
window.show();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question