Created
January 14, 2013 03:49
-
-
Save anonymous/4527649 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 = Titanium.UI.createWindow(); | |
var imageView = Ti.UI.createImageView({height: Ti.UI.FILL, width: Ti.UI.Fill}); | |
win.add(imageView); | |
Titanium.Media.showCamera({ | |
success:function(event) | |
{ | |
Ti.API.info('#### Camera Success'); | |
var cropRect = event.cropRect; | |
var image = event.media; | |
Ti.API.info(image.length); | |
var filename = Titanium.Filesystem.tempDirectory + "/"+ 'camera_photo' + new Date().getTime() + ".png"; | |
Ti.API.info(filename); | |
var f = Titanium.Filesystem.getFile(filename); | |
Ti.API.info(f.nativePath); | |
if (f.exists()) { | |
Ti.API.info('The file exist , trying to delete it before using it :' + f.deleteFile()); | |
f = Titanium.Filesystem.getFile(filename); | |
} | |
f.write(image); | |
alert('Camera Success! The file size is '+f.size+' bytes.\n Now trying to assign it to an image on the screen (this may fail for hi res images)') | |
imageView.image = f.nativePath; | |
}, | |
cancel:function() | |
{ | |
Ti.API.info('#### Camera Cancel'); | |
}, | |
error:function(error) | |
{ | |
// create alert | |
Ti.API.info('#### Camera Error'); | |
var a = Titanium.UI.createAlertDialog({title:'Camera'}); | |
// set message | |
if (error.code == Titanium.Media.NO_CAMERA) | |
{ | |
a.setMessage('Device does not have video recording capabilities'); | |
} | |
else | |
{ | |
a.setMessage('Unexpected error: ' + error.code); | |
} | |
// show alert | |
a.show(); | |
}, | |
allowEditing:true | |
}); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment