-
-
Save AngelkPetkov/422f079c0fcde8a11b6cee4c36130598 to your computer and use it in GitHub Desktop.
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
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