Created
May 27, 2011 00:38
-
-
Save jonalter/994417 to your computer and use it in GitHub Desktop.
camera with overlay
This file contains hidden or 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({ 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