Skip to content

Instantly share code, notes, and snippets.

@brannondorsey
Created May 5, 2016 02:14
Show Gist options
  • Select an option

  • Save brannondorsey/276f048a14f04c0bfca4b4c1a09d41e0 to your computer and use it in GitHub Desktop.

Select an option

Save brannondorsey/276f048a14f04c0bfca4b4c1a09d41e0 to your computer and use it in GitHub Desktop.
Fit Image/video to app window (using OpenFrameworks)
float width = ofGetWidth();
float height = ofGetHeight();
float aspect = width / height;
// horizontal black bars
if (aspect <= player.getWidth()/player.getHeight()) {
float vHeight = (player.getHeight() * width) / player.getWidth();
player.draw(0,
(height - vHeight) * 0.5,
width,
vHeight);
} else { // vertical black bars
float vWidth = (player.getWidth() * height) / player.getHeight();
player.draw((width - vWidth) * 0.5,
0,
vWidth,
height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment