Chapter 12

Using the Camera

What's in this chapter?

Capturing images with the Android camera

Creating your own Activity for controlling the camera

Capturing images continuously during camera preview

Creating a simple barcode reader that uses camera preview

The Android platform creates an incredible opportunity for image processing, because it offers an image processing system that is universally available, handheld, inexpensive, easy to program, networked, and provides processing power equivalent to a low-end personal computer. This chapter shows you how to begin to make use of this remarkable platform by focusing on image processing that happens immediately after capturing the image.

Using the Camera Activity

If all you want to do is capture an image, things could not be much easier. All you have to do is create an Intent with the action MediaStore.ACTION_IMAGE_CAPTURE, passing it a filename as extended data with the name MediaStore.EXTRA_OUTPUT. Then call startActivityForResult(), passing your Intent and an identifier identifying this Intent to your onActivityResult() method.

What this does is fire up the camera application, giving the user the opportunity to control the camera parameters themselves and take a picture. The picture is stored into your chosen file, and your onActivityResult() method is called when it is done.

Listing 12.1 shows the key steps, and SimpleCaptureActivity in the provided code gives you the complete application.

Listing 12.1: Taking a photo

private ...

Get Professional Android Sensor Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.