Loading Large Images
-
Hi,
I want to load a large .png (~18000x10000), however the standard way does not work as the image is not loaded when using either QPIxmap/QImage in conjunction with their respecitve load functions.
I also tried using QImageReader, but the reader also does not seem to load the image properly.
QImageReader* reader = new QImageReader("largeImg.png"); QImage img; QRect s; s.setX(0); s.setY(0); s.setWidth(1920); s.setHeight(1080); reader->setClipRect(s); img = reader->read(); bool b = img.isNull() //true
It works for smaller images (smaller in resolution only). Is there something else i have to change or do? Can/should i manually allocate the memory?
-
Hi,
I want to load a large .png (~18000x10000), however the standard way does not work as the image is not loaded when using either QPIxmap/QImage in conjunction with their respecitve load functions.
I also tried using QImageReader, but the reader also does not seem to load the image properly.
QImageReader* reader = new QImageReader("largeImg.png"); QImage img; QRect s; s.setX(0); s.setY(0); s.setWidth(1920); s.setHeight(1080); reader->setClipRect(s); img = reader->read(); bool b = img.isNull() //true
It works for smaller images (smaller in resolution only). Is there something else i have to change or do? Can/should i manually allocate the memory?
-
Hello!
What is the size of this image? Also, do you load it from the app resource or drive?
-
Hello!
What is the size of this image? Also, do you load it from the app resource or drive?
Even you set a clipRect() doesn't mean the image doesn't needed to be loaded into memory first. Some image formats may support this but even then the image plugin would need support for it (which png has not but jpeg does). So you need at 18000 *10000 * 4 bytes = ~686MB of free contiguous memory if it's a 32bit image.
What does QImageReader::error() returns or do you see some errors on the command line?btw: why do you create reader on the heap? It's leaking...
-
Even you set a clipRect() doesn't mean the image doesn't needed to be loaded into memory first. Some image formats may support this but even then the image plugin would need support for it (which png has not but jpeg does). So you need at 18000 *10000 * 4 bytes = ~686MB of free contiguous memory if it's a 32bit image.
What does QImageReader::error() returns or do you see some errors on the command line?btw: why do you create reader on the heap? It's leaking...
@Christian-Ehrlicher The error function returns invalidImageData after the read(). I dont get any other errors.
There is no particular reason its on the heap, im just debugging, but im also deleting it later.
The exact size of the image is 12300x7200, 404kb in png format (but the format doesnt really matter).In theory i could also split the image in multiple parts and then tranlate the individual parts in the scene accordingly, but im not yet sure how i could do that.
-
@Christian-Ehrlicher The error function returns invalidImageData after the read(). I dont get any other errors.
There is no particular reason its on the heap, im just debugging, but im also deleting it later.
The exact size of the image is 12300x7200, 404kb in png format (but the format doesnt really matter).In theory i could also split the image in multiple parts and then tranlate the individual parts in the scene accordingly, but im not yet sure how i could do that.
You mean InvalidDataError ? Please check what canRead() and format() returns. Also make sure QImageReader::allocationLimit() is large enough.
-
You mean InvalidDataError ? Please check what canRead() and format() returns. Also make sure QImageReader::allocationLimit() is large enough.
@Christian-Ehrlicher Setting the allocationLimit solves the issue. Thank you.