J
J
JuniorHelp2020-10-14 14:56:44
Qt
JuniorHelp, 2020-10-14 14:56:44

How to create a bmp file and write an array of bytes there?

The bytes are stored in a QByteArray
Option to create a .bmp file using QFile successfully creates a file, but when opening such a file, an error occurs
"BMP image has bogus header data"

QFile newDoc("fileName.bmp");

    if(newDoc.open(QIODevice::WriteOnly)){
        newDoc.write(image_byte);
    }

Another option does not create a file
QImage image;
         QByteArray ba;
         QBuffer buffer(&ba);
         buffer.open(QIODevice::WriteOnly);
         image.save(&buffer, "PNG");


QImage img;
        img.loadFromData(image_byte);
        QPixmap px = QPixmap::fromImage(img);
        img.save("my_image","BMP");


The bytes in the array are taken from the XML
if(domElement.tagName() == "image"){
                image_byte.append(domElement.text());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-10-14
@JuniorHelp

Do these bytes even represent a valid bmp with a header? Or is it just pixels?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question