Skip to content

Instantly share code, notes, and snippets.

@AngelkPetkov
Last active July 13, 2016 18:55
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 AngelkPetkov/422f079c0fcde8a11b6cee4c36130598 to your computer and use it in GitHub Desktop.
Save AngelkPetkov/422f079c0fcde8a11b6cee4c36130598 to your computer and use it in GitHub Desktop.
var win = Ti.UI.createWindow({
backgroundColor: 'white'
}),
takePic = Ti.UI.createButton({
title : "Take picture",
width : "90%",
height : 40,
top : 0,
}),
currPic = null,
imageView = null;
function takePicture() {
Titanium.Media.showCamera({
success:function(event)
{
var image = event.media;
currPic = image;
imageView = Titanium.UI.createImageView({
image: currPic,
top: 4,
left: 4,
width: 400,
height: 400,
});
btnTransform.enabled = true;
win.add(imageView);
},
cancel:function()
{
},
error:function(error)
{
},
saveToPhotoGallery:false,
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
};
takePic.addEventListener("click",function(e) {
if (!currPic) {
Ti.Media.requestCameraPermissions(takePicture);
} else {
takePicture();
}
});
win.add(takePic);
var btnTransform = Titanium.UI.createButton({
title: 'Crop with SDK',
bottom: 4, left: 125,
width: '40%', height: 60,
enabled:false
});
btnTransform.addEventListener('click', function (e) {
if (currPic != null) {
Ti.API.info("Cropped!");
var newBlob = currPic.imageAsCropped({ width:currPic.width, height:currPic.height, x:0, y:0 });
imageView.image = newBlob;
imageView.size = { width:newBlob.width, height:newBlob.height };
}
});
win.add(btnTransform);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment