Problem displaying big image

I’ve a problem trying to display large images. I’ve encountered the problem on a RaspberryPi (4, with 4GB ram, GPU memory up to 512MB, Raspian), but reading the forum i’ve found it appearing on varius platforms, so i think it’s not related to Raspi.
So, i’ve an image (PNG image data, 4963 x 3513, 8-bit/color RGB, non-interlaced). If i’m not wrong, it should occupy about 400MB in memory.
Load fine (with bigImage.load("big_image.png")), but when i try to draw

void ofApp::draw(){

nothing but a white background is shown… Reducing image size (even with resize() method), make it display correctly (a dimension of 4019x2844 it’s ok).

What i’d like to know/understand:

  • How can i know what is the max dimension of an image that i can display?
  • load() or draw() should’n be fail, when the image is too big?
  • to avoid resize the image, the only way is to create another image extracting a subimage of the big one? (and of curse, updating it, depending of what i want to display)


1 Like

yes there is a maximum texture size that gpus support, it depends on the hardware and surely it’s much smaller for the raspberry than desktop computers.

As you say ofTexture should fail if you try to load an image that is bigger than it’s supported, if you want to open an issue on github about it, that would be really useful

there’s no direct OF call to know the max texture size but you can just use opengl:

int maxTextureSize;
 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);

after that call maxTextureSize should contain the maximum allowed texture size for that graphics card.

the only other way except for resizing is to cut the image in tiles and use several images to load and show them


Ok, i’ve tryied and it seems that on a Raspberry Pi4 the maximum texture size is 4096, so i can load an image with maximum size of 4096x4096, if i’m not wrong.

I’ll open a gitHub issue to make fail loading images too big.

I’ve made a simple test to extract a portion of the original image, equal to screen size, like this:

ofImage img1, img2;
img1.loadImage("big_image.png"); //in setup()
img2.cropFrom(img1, mouseX, mouseY, ofGetWidth(), ofGetHeight()); //in update()
img2.draw(0,0); //in draw()

but it’s quite slow… In processing i’ve made something similar acessing image pixel, as explained here
It’s possible to do something similar in OF? maybe with getPixels()? Or will be still really slow?

yes calling cropImage in update will be slow on a raspberry. i would just divide the original image in as many 4096x4096 chunks as you need, in setup, and draw those that need to be drawn, there’s probably some tiled renderer addon that does something similar already

ok, i’ll take a look.