Using Intents to Take Pictures

The easiest way to take a picture using the device camera is using the action_image_capture Media Store static constant in an Intent passed to startActivityForResult.

startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),

TAKE_PICTURE);

This will launch the camera Activity, allowing users to modify the image settings manually, and preventing you from having to rewrite the entire camera application.

The image capture action supports two modes, thumbnail and full image.

> Thumbnail By default, the picture taken by the image capture action will return a thumbnail Bitmap in the data extra within the Intent parameter returned in onActivityResult. As shown in Listing 11-11, call getParcelableExtra specifying the extra name data on the Intent parameter to return the thumbnail as a Bitmap.

> Full image If you specify an output URI using a MediaStore.EXTRA_0UTPUT extra in the launch Intent, the full-size image taken by the camera will be saved to the specified location. In this case no thumbnail will be returned in the Activity result callback and the result Intent data will be null.

Listing 11-11 shows how to use the image capture action to capture either a thumbnail or full image using an Intent.

LISTING 11-11: Taking a picture using an Intent

Available for download on private static int TAKE_PICTURE = 1; Wrox.com private Uri outputFileUri;

private void getThumbailPicture() {

Intent intent = new Intent(MediaStore.ACTI0N_IMAGE_CAPTURE); startActivityForResult(intent, TAKE_PICTURE);

private void saveFullImage() {

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

File file = new File(Environment.getExternalStorageDirectory(),

"test.jpg"); outputFileUri = Uri.fromFile(file);

intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); startActivityForResult(intent, TAKE_PICTURE);

©Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_PICTURE) { Uri imageUri = null;

// Check if the result includes a thumbnail Bitmap if (data != null) {

Bitmap thumbnail = data.getParcelableExtra("data"); // TODO Do something with the thumbnail

// TODO Do something with the full image stored // in outputFileUri

Once you have taken the picture, you can either add it to the Media Store as shown later in this chapter, or process it for use within your application before removing it.

Understanding Adobe Photoshop Features You Will Use

Understanding Adobe Photoshop Features You Will Use

Adobe Photoshop can be a complex tool only because you can do so much with it, however for in this video series, we're going to keep it as simple as possible. In fact, in this video you'll see an overview of the few tools and Adobe Photoshop features we will use. When you see this video, you'll see how you can do so much with so few features, but you'll learn how to use them in depth in the future videos.

Get My Free Video


Post a comment