Skip to content

Instantly share code, notes, and snippets.

@benjaminbojko
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminbojko/f38e88daab3a10b5ee7c to your computer and use it in GitHub Desktop.
Save benjaminbojko/f38e88daab3a10b5ee7c to your computer and use it in GitHub Desktop.
[Cinder] Different Image Sizing Snippets
using namespace ci;
enum Sizing {
//! Native resolution with no scaling
Native,
//! Fit exactly by scaling x/y independently
Fit,
//! Resize to fit at least mSize while maintaining aspect ratio
Aspect,
//! Resize to fit at most mSize while maintaining aspect ratio
AspectFit,
//! Resize to fit at least mSize while maintaining aspect ratio and cropping outside of mSize
AspectFill
};
// ...
const void drawTexture(const gl::Texture& aTexture, const Rectf& aTargetRect, const Sizing aSizing = Native) {
switch (aSizing) {
case AspectFit:
gl::draw(aTexture, Rectf(aTexture.getBounds()).getCenteredFit(aTargetRect, true));
break;
case AspectFill:
gl::draw(aTexture, Area(aTargetRect.getCenteredFit(aTexture.getBounds(), true)), aTargetRect);
break;
case Aspect:
gl::draw(aTexture, Area(aTargetRect.getCenteredFit(aTexture.getBounds(), true)));
break;
case Fit:
gl::draw(aTexture, aTargetRect);
break;
default:
case Native:
gl::draw(aTexture);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment