Capture Media

This documentation provides guidelines on capturing images and recording videos using the TruVideo Camera SDK. The SDK offers simple methods to integrate camera functionalities into your application.

Prerequisites

  • Ensure you have integrated the TruVideo Core SDK into your project and completed with the authentication process

Capturing an Image

To capture an image, follow these steps:

Step 1 : CameraResult return by initCameraScreen

interface CameraResult {
  id: string,
  createdAt: number,
  filePath: string,
  type: CameraMediaType,
  lensFacing: LensFacing,
  orientation: Orientation,
  resolution: Resolution,
  duration: number,
}

Step 2: Create new configuration to give to the camera

const cameraConfiguration: CameraConfiguration = {

    lensFacing: LensFacing.Front,
    //lensFacing: LensFacing.Back,

    flashMode: FlashMode.Off,
    //flashMode: FlashMode.On

    orientation: Orientation.Portrait,
    //orientation: Orientation.LandscapeLeft,
    //orientation: Orientation.LandscapeRight,
    //orientation: Orientation.PortraitReverse,
    //orientation: Orientation.Portrait,

    outputPath: '',
    frontResolutions: [],
    frontResolution: 'nil',
    backResolutions: [],
    backResolution: 'nil',
    mode: CameraMode.image(),
    //mode: CameraMode.video()
    //mode: CameraMode.videoAndImage()
    
    imageFormat : ImageFormat.JPEG
    // imageFormat : ImageFormat.PNG
  };

Step 3 : Present the camera with the configuration

// cameraConfiguration will be the configuration from above 
initCameraScreen(cameraConfiguration)
      .then((res) => {
         //handle response
         const mediaItem : CameraResult[] = res;

      })
      .catch((err) => {
         //handle error
        console.log('err', err);
      });

Finalize :

After completing this steps the function should look like

// import the required dependency 
import {    
    initCameraScreen,    
    LensFacing,    
    FlashMode,    
    Orientation,    
    CameraMode,    
    CameraConfiguration,
    CameraResult,
    ImageFormat
} from '@trunpm/truvideo-react-turbo-camera-sdk';

// call this function to create camera
const initCamera = async () => {    
    // create configuration
    var cameraConfiguration  :  CameraConfiguration = {        
        lensFacing: LensFacing.Back,        
        flashMode: FlashMode.Off,        
        orientation: Orientation.Portrait,       
        outputPath: "",        
        frontResolutions: [],        
        frontResolution: null,        
        backResolutions: [],        
        backResolution: null,        
        mode: CameraMode.videoAndImage(),
        imageFormat : ImageFormat.JPEG   
    }   
    // start camera 
    initCameraScreen(cameraConfiguration)         
        .then((response) => {            
            const mediaItems: CameraResult[] = response;                                   
        })        
        .catch((err) => {            
            console.log('err', err);        
        });    
};


// use it with button click 
<TouchableOpacity style={styles.button} onPress={initCamera}>    
    <Text style={styles.buttonText}>Camera</Text>
</TouchableOpacity>

Last updated

Was this helpful?