Capture

This page shows how to capture images with connected camera device using RICOH Camera Wireless SDK. RICOH Camera Wireless SDK supports single frame shooting.

Depending on the model, there are some captures not supported. When not supported capture is started, CameraSDKError.unsupportedOperation is thrown.

Contents

The following protocols and classes are used when you capture images:

CameraImage

  • The CameraImage protocol represents image information and image data.
  • This protocol includes methods for obtaining image information and image data.

CameraEventListener

  • The CameraEventListener protocol is a event listener which receives notifications from camera devices.

Capture Still Images

Use the startCapture method with CaptureMethod.stillImage and the withFocus argument true to capture still image with connected camera device.

let captureMethod = CaptureMethod()
var response = cameraDevice.getCaptureSettings(settings: [captureMethod])
if response.result == Result.error {
    return
}

if captureMethod != CaptureMethod.stillImage {
    if captureMethod.availableSettings.contains(CaptureMethod.stillImage) {
        response =
            cameraDevice.setCaptureSettings(settings: [CaptureMethod.stillImage])
        if response.result == Result.error {
            return
        }
    } else {
        print("Capturing StillImage is not available.")
        return
    }
}

let startCaptureResponse: StartCaptureResponse
do {
    try startCaptureResponse = cameraDevice.startCapture(withFocus: true)
} catch {
    print("Capturing StillImage is not supported.")
    return
}

if startCaptureResponse.result == Result.ok {
    print("Capturing StillImage has started."
        + " Capture ID: \(startCaptureResponse.capture?.id)")
} else {
    print("Capturing StillImage is FAILED."
        + "detail: \(startCaptureResponse.errors[0].message)")
}

Focus and Capture Still Images

If you want to capture images after focusing, use the focus method and the startCapture method with the withFocus argument false.

var response: Response
do {
    try response = cameraDevice.focus()
} catch {
    print("Focus is not supported.")
    return
}

if response.result == Result.ok {
    print("Focus has started.")
} else {
    print("Focus is FAILED. detail: \(response.errors[0].message)")
    return
}

let captureMethod = CaptureMethod()
response = cameraDevice.getCaptureSettings(settings: [captureMethod])
if response.result == Result.error {
    return
}

if captureMethod != CaptureMethod.stillImage {
    if captureMethod.availableSettings.contains(CaptureMethod.stillImage) {
        response =
            cameraDevice.setCaptureSettings(settings: [CaptureMethod.stillImage])
        if response.result == Result.error {
            return
        }
    } else {
        print("Capturing StillImage is not available.")
        return
    }
}

let startCaptureResponse: StartCaptureResponse
do {
    try startCaptureResponse = cameraDevice.startCapture(withFocus: false)
} catch {
    print("Capturing StillImage is not supported.")
    return
}

if startCaptureResponse.result == Result.ok {
    print("Capturing StillImage has started."
        + " Capture ID: \(startCaptureResponse.capture?.id)")
} else {
    print("Capturing StillImage is FAILED."
        + " detail: \(startCaptureResponse.errors[0].message)")
}

Check Capture Status

Use the CaptureState returned the state property of the Capture protocol to check capture status. One of the supported values of the status is complete, which means the camera device has finished capturing.

You can obtain the Capture class with the three ways below:

The StartCaptureResponse class explained in sections above provides a Capture called capture property.

let startCaptureResponse = cameraDevice.startCapture(withFocus: false)
if startCaptureResponse.result == Result.ok {
    let capture = startCaptureResponse.capture
    print("Capture state is \(capture?.state)");
}

The CameraDevice class has a CameraStatus called status property. The CameraStatus class provides a Capture called currentCapture property.

if let currentCapture = cameraDevice.status.currentCapture {
    print("Capture state is \(currentCapture.state)");
}

The captureComplete method of the CameraEventListener class is invoked when the camera device has finished capturing.

class UserEventListener: CameraEventListener {
    // Capture Complete
    func captureComplete(sender: CameraDevice, capture: Capture) {
        print("Capture Complete. Caputure ID: \(capture.id)")
    }
}

Obtain Captured Image

Use the imageStored method of the CameraEventListener class to obtain the image you captured.

class UserEventListener: CameraEventListener {
    // Image Stored
    func imageStored(sender: CameraDevice, image: CameraImage) {
        print("Image Stored. Image Name: \(image.name)")
    }
}

See Also

  • Image Handling - Demonstrates image acquisition.
  • Capture Settings - Describes available capture settings such as capturing without saving data on camera storage.
  • Events - Describes events such as captureComplete and imageStored.