Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2013 03:49
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 anonymous/4527649 to your computer and use it in GitHub Desktop.
Save anonymous/4527649 to your computer and use it in GitHub Desktop.
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