c++ - Saving a QImage to QBuffer -


i doing this:

qimage image(width, height, qimage::format_rgb32); frame.fill(qcolor(255, 255, 255).rgb());  qbuffer buffer; buffer.open(qbuffer::readwrite); qdatastream out(&buffer); 

option 1:

out << image; 

option 2:

out.writerawdata((char *) image.constbits(), image.bytecount()) ; 

option 1 pretty slow , not sure if option 2 correct way do?

you can use qimage::save write directly qiodevice, buffer or file.

image.save(buffer); 

option 2 looks pretty gross compared option 1; prefer option 1 aesthetically. prefer api mentioned on both options give.

you can read more image read/write here.


Comments