Smaller version of image

Hi all, new to OF here.

I’m trying to write a 2D vector of object as pixels to an image and display the image. It looks like a smaller version of the image is pasted multiple times, not really sure what’s going wrong.

void ofApp::draw(){
	for (int i = 0; i < 1; i++) {
		update();
		swap();
	}

	img.grabScreen(0, 0, appWidth, appHeight);
	ofPixels& pixels = img.getPixels();
	for (int i = 0; i < appWidth; i++) {
		for (int j = 0; j < appHeight; j++) {
			Cell* spot = grid[i][j];
			float a = spot->a;
			float b = spot->b;
			int pos = i + j * appWidth;
			pixels[pos] = (a - b) * 255;
		}
	}
	img.update();
	img.draw(0, 0);
}

Hey @darthgrayter,

An RGB image has 3 channels (3 pixels per color), while an RGBA has 4 and a grayscale has 1. So the total number of pixels is width x height x number of channels, which you can get from ofPixels::getNumChannels().

1 Like

Great, that works now! The image is fullscreen

One thing you might want to do too is to do all the updating of the image in ofApp::update(), and then draw it in ofApp::draw(). This gives the graphics pipeline a chance to render the image to the screen. ofImage::update() will update the texture of the image (so, the image in memory of the gpu), and things can get too busy in the draw portion of the cycle if an image is updated there before it is drawn.

1 Like