# toBuffer method

Uint8List toBuffer(

1. ImageFormat documentImageFormat,
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 documentImageFormat The image format to export the image to. param compressionLevel The compression level to be applied. return Buffer that receives the image data. throws DocumentException An error has occurred during Document Library execution.

## Implementation

    Uint8List toBuffer(ImageFormat documentImageFormat, double compressionLevel) {
      Pointer<UnsignedChar> pData = nullptr;
      Pointer<Int> pDataSize = calloc();
      pDataSize[0] = -1;
      try {
        var err = documentSDK.id3DocumentImage_ToBuffer(_pHandle.value, documentImageFormat.value, compressionLevel, pData, pDataSize);
        if (err == DocumentError.insufficientBuffer.value) {
          pData = calloc.allocate(pDataSize.value);
          err = documentSDK.id3DocumentImage_ToBuffer(_pHandle.value, documentImageFormat.value, compressionLevel, pData, pDataSize);
        }
        if (err != DocumentError.success.value) {
          throw DocumentException(err);
        }
        final vData = Uint8List.fromList(pData.cast<Uint8>().asTypedList(pDataSize.value));
        return vData;
      } finally {
        calloc.free(pData);
        calloc.free(pDataSize);
      }
    }