toBuffer method

Uint8List toBuffer()

Exports the face object to a buffer.

return The buffer to which the face object is exported. throws FaceException An error has occurred during Face Library execution.

Implementation

Uint8List toBuffer() {
  Pointer<UnsignedChar> pData = nullptr;
  Pointer<Int> pDataSize = calloc();
  pDataSize[0] = -1;
  try {
    var err = faceSDK.id3DetectedFace_ToBuffer(_pHandle.value, pData, pDataSize);
    if (err == FaceError.insufficientBuffer.value) {
      pData = calloc.allocate(pDataSize.value);
      err = faceSDK.id3DetectedFace_ToBuffer(_pHandle.value, pData, pDataSize);
    }
    if (err != FaceError.success.value) {
      throw FaceException(err);
    }
    final vData = Uint8List.fromList(pData.cast<Uint8>().asTypedList(pDataSize.value));
    return vData;
  } finally {
    calloc.free(pData);
    calloc.free(pDataSize);
  }
}