fromBuffer static method

DocumentImage 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 document image. throws DocumentException An error has occurred during Document Library execution.

Implementation

static DocumentImage fromBuffer(Uint8List? data, PixelFormat pixelFormat) {
  DocumentImage documentImage = DocumentImage();
  Pointer<UnsignedChar>? pData;
  if (data != null) {
  	pData = calloc.allocate<UnsignedChar>(data.length);
  	pData.cast<Uint8>().asTypedList(data.length).setAll(0, data);
  }
  try {
    var err = documentSDK.id3DocumentImage_FromBuffer(documentImage.handle, pData ?? nullptr, data?.length ?? 0, pixelFormat.value);
    if (err != DocumentError.success.value) {
      documentImage.dispose();
      throw DocumentException(err);
    }
    return documentImage;
  } finally {
    if (pData != null) {
      calloc.free(pData);
    }
  }
}