toBuffer method

Uint8List toBuffer(
  1. ImageFormat imageFormat,
  2. double compressionLevel
)

Exports the image to a buffer. The compression level meaning depends on the algorithm used:

  • For JPEG compression, the value is the expected quality and may vary from 1 to 100.
  • For JPEG2000 compression, the value is the compression rate and may vary from 1 to 512.
  • For PNG compression, the value is the compression rate and may vary from 1 to 10.
  • For all other formats, the value is ignored.

param imageFormat The image format to export the image to. param compressionLevel The compression level to be applied. return Buffer that receives the image data. throws FaceException An error has occurred during Face Library execution.

Implementation

Uint8List toBuffer(ImageFormat imageFormat, double compressionLevel) {
  Pointer<UnsignedChar> pData = nullptr;
  Pointer<Int> pDataSize = calloc();
  pDataSize[0] = -1;
  try {
    var err = faceSDK.id3FaceImage_ToBuffer(_pHandle.value, imageFormat.value, compressionLevel, pData, pDataSize);
    if (err == FaceError.insufficientBuffer.value) {
      pData = calloc.allocate(pDataSize.value);
      err = faceSDK.id3FaceImage_ToBuffer(_pHandle.value, imageFormat.value, compressionLevel, 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);
  }
}