Skip to content

Instantly share code, notes, and snippets.

@jonalter
Created May 27, 2011 00:38
Show Gist options
  • Select an option

  • Save jonalter/994417 to your computer and use it in GitHub Desktop.

Select an option

Save jonalter/994417 to your computer and use it in GitHub Desktop.
camera with overlay
var win = Ti.UI.createWindow({ fullscreen: true });
var cameraOverlay = Ti.UI.createView();
var cameraButton = Ti.UI.createButton({
title:"Take Picture",
bottom: 10
});
cameraButton.addEventListener('click', function(e){
Ti.Media.takePicture();
});
cameraOverlay.add(cameraButton);
var open = Ti.UI.createButton({
title: 'Open',
bottom: 100,
height: 40,
width: 200
});
open.addEventListener('click', function(){
Titanium.Media.showCamera({
success:function(event)
{
var cropRect = event.cropRect;
var image = event.media;
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO)
{
var imageView = Ti.UI.createImageView({
width:win.width,
height:win.height,
image:event.media
});
win.add(imageView);
}
else
{
alert("got the wrong type back ="+event.mediaType);
}
},
cancel:function()
{
},
error:function(error)
{
// create alert
var a = Titanium.UI.createAlertDialog({title:'Camera'});
// set message
if (error.code == Titanium.Media.NO_CAMERA)
{
a.setMessage('Please run this test on device');
}
else
{
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
},
saveToPhotoGallery:true,
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO],
overlay: cameraOverlay
});
});
win.add(open);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment