fromBuffer static method

Image fromBuffer(
  1. Uint8List? data,
  2. PixelFormat pixelFormat
)

Creates an Image from the specified data buffer.

param data A buffer that contains the image data. param pixelFormat The destination pixel format to convert the input to. return The newly created image. throws FaceException An error has occurred during Face Library execution.

Implementation

static Image fromBuffer(Uint8List? data, PixelFormat pixelFormat) {
  Image image = Image();
  Pointer<UnsignedChar>? pData;
  if (data != null) {
  	pData = calloc.allocate<UnsignedChar>(data.length);
  	pData.cast<Uint8>().asTypedList(data.length).setAll(0, data);
  }
  try {
    var err = faceSDK.id3FaceImage_FromBuffer(image.handle, pData ?? nullptr, data?.length ?? 0, pixelFormat.value);
    if (err != FaceError.success.value) {
      image.dispose();
      throw FaceException(err);
    }
    return image;
  } finally {
    if (pData != null) {
      calloc.free(pData);
    }
  }
}