Time for action – using the camera
Let's get started with the camera. This is a simple demonstration on how you can incorporate the camera into your app.
This example is available for download or browse at https://github.com/myleftboot/Chapter-7-camera. To use the camera, perform the following steps:
Create a new blank mobile app by clicking on File | New | Titanium Project. Don't use a template as it will just generate code that gets in the way.
Create the window for the app:
var win1 = Titanium.UI.createWindow({ backgroundColor:'#fff' });
The layout for this example will be a button, and below that an image view, which will show the picture taken by the camera. All simple stuff!
var options = Ti.UI.createView({layout: 'vertical'}); var showCamera = Ti.UI.createButton({title: 'Show Camera'}); var thePhoto = Ti.UI.createImageView({height: '30%', width: '30%'}); options.add(showCamera); options.add(thePhoto); win1.add(options);
Add a function to update the image with the photograph. It...