Created
May 5, 2016 02:14
-
-
Save brannondorsey/276f048a14f04c0bfca4b4c1a09d41e0 to your computer and use it in GitHub Desktop.
Fit Image/video to app window (using OpenFrameworks)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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