Best way to zoom an image

I would like to learn the best way to zoom a image .
Calling ofImage resize() function for every update (when FPS is set to 25) is causing delays when the image gets bigger. Can someone suggest a better way to achieve the same. Is it possible to have a smooth zoom of the ofImage

struct ZoomingRectangle
{
  ofPoint   pos, dimension;
  double    increment_size;
  int       canvas_width, canvas_height;
  int       final_width, final_height;
  int       initial_width, initial_height;
  double    scale_value;
  ofImage   game_board, game_board_copy;

  void setup(int init_w, int init_h, int final_w, double inc_value)
  {
    canvas_width = ofGetWidth();
    canvas_height = ofGetHeight();

initial_width = init_w;
initial_height = init_h;
increment_size = inc_value;
final_width = final_w;
final_height = final_w * init_h / init_w;

game_board.loadImage("game_board_1.png");
game_board_copy = game_board;
reset_dimensions();
  }

void update()
{
if (dimension.x < final_width)
{
  dimension *= (1 + increment_size);
  scale_value *= (1 + increment_size);
}
else
{
  reset_dimensions();
}

  game_board.resize(dimension.x, dimension.y);
  pos.x = (canvas_width - dimension.x) / 2;
  pos.y = (canvas_height - dimension.y) / 2;
}

void draw()
{
  ofSetColor(114, 176, 149);
  ofRect(pos, dimension.x, dimension.y);
  game_board.draw(pos.x, pos.y);
}

void reset_dimensions()
{
  dimension.x = initial_width;
  dimension.y = initial_height;
  dimension.z = 0;

  pos.x = (canvas_width - dimension.x) / 2;
  pos.y = (canvas_height - dimension.y) / 2;
  pos.z = 0;  

  player_pos.x = player_pos.y = player_pos.z = 0;
  game_board = game_board_copy;
  scale_value = 1.0;
}

};

If you use ofScale() with you can simply draw a scaled version of the image with the GPU rather than resizing the actual pixels every time.

See more about ofScale() here:

Thanks

I will try it out

Hi,

When you draw an ofImage you can also specify the width and height you want to draw it in, with the GPU doing the heavy lifting.

http://openframeworks.cc/documentation/graphics/ofImage.html#show_draw