Created
January 21, 2016 21:59
-
-
Save nitrag/3207abe888089db52f47 to your computer and use it in GitHub Desktop.
MaxImage.js
This file contains 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
exports.createView = function(args) { | |
var imageView = Ti.UI.createImageView(args); | |
imageView.setMaxImage = function(url, maxWidth, maxHeight){ | |
var preview = Ti.UI.createImageView(); | |
Ti.API.info("ImageView's width = " + imageView.getWidth()); | |
preview.addEventListener('load', function(e){ | |
Ti.API.info("Loaded preview, resizing..."); | |
var ratioX = imageView.getWidth() / image.width(); //hardcoded to imageView's max width since this is static to my needs, change for full functionality | |
var ratioY = imageView.getWidth() / image.height(); //hardcoded for a square image for my needs, change to maxHeight for your needs | |
var ratio = Math.min(ratioX, ratioY); | |
var w = imageWidth * ratio; | |
var h = imageHeight * ratio; | |
imageView.setWidth(w); | |
imageView.setHeight(h); | |
imageView.image = url; | |
}); | |
preview.image = url; | |
}; | |
return imageView; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment