# TakePicture¶

Goal - Take pictures with the robot camera.

// Build the action.
val takePicture: TakePicture = TakePictureBuilder.with(qiContext).build()

// Run the action synchronously.
val result: TimestampedImageHandle = takePicture.run()


// Build the action.
TakePicture takePicture = TakePictureBuilder.with(qiContext).build();

// Run the action synchronously.
TimestampedImageHandle result = takePicture.run();



Typical usage - You want to take pictures of what Pepper is seeing.

## How it works¶

Run the TakePicture action when you want to capture an image.

// Build the action.
val takePicture: TakePicture = TakePictureBuilder.with(qiContext).build()

// Run the action synchronously.
val result: TimestampedImageHandle = takePicture.run()


// Build the action.
TakePicture takePicture = TakePictureBuilder.with(qiContext).build();

// Run the action synchronously.
TimestampedImageHandle result = takePicture.run();



Running a TakePicture action returns a TimestampedImageHandle.

Use the getTime() method of the returned TimestampedImageHandle object to get the timestamp associated with the image. See Timestamps.

Log.i(TAG, "Picture taken at: \${result.time}")


Log.i(TAG, "Picture taken at: " + result.getTime());



To retrieve the data of an image captured with a TakePicture action, the image data needs to be remotely copied from the robot head to the tablet. Copying remote data is an expensive operation, and it might take some time. That is why the run() method does not directly return a copy of the data, but returns instead an object that acts as a proxy: this lets you control when you want to make the copy.

Use the getImage() method of the returned TimestampedImageHandle object to get an EncodedImageHandle object; and use its getValue() method to effectively copy the image data.

// Retrieve the image data.
// 1. get a proxy to access the data
val encodedImageHandle: EncodedImageHandle = result.image
// 2. copy the remote data value
val encodedImage: EncodedImage = encodedImageHandle.value
// Create a ByteBuffer from the retrieved data.
val data: ByteBuffer = encodedImage.data


// Retrieve the image data.
// 1. get a proxy to access the data
EncodedImageHandle encodedImageHandle = result.getImage();
// 2. copy the remote data with the getValue() method
EncodedImage encodedImage = encodedImageHandle.getValue();
// Create a ByteBuffer from the retrieved data.
ByteBuffer data = encodedImage.getData();