PDA

View Full Version : QImage and Memoey Mapped Files



Leviathan
25th July 2010, 07:16
Hi. I want bind QImage to the MMF file to manipulate the image without the cost of memory directly on the disc. Unfortunately, my code creates a copy in memory.


QFile file("Boston City Flow.jpg");
if(!file.open(QIODevice::ReadOnly))
QMessageBox::information(this, "Error", "Error");

qint64 size = file.size();
unsigned char *mmf = file.map(0, size);

QImage image;
image.loadFromData(mmf, size, NULL);

My program needs to handle very large images.

tbscope
25th July 2010, 08:36
Use streams and read/write in smaller packages.

Leviathan
25th July 2010, 09:25
how? can you give an example for jpeg?

wysota
25th July 2010, 09:57
JPEG requires all data to be loaded to be able to manipulate it. mmapping a jpeg would do you no good as the data has to be decompressed and reassembled before it actually becomes an image. You could mmap a BMP file and even maybe an uncompressed PNG file but surely not a JPEG file, regardless if you're using Qt or not.