.. index:: 
  !DocumentImage.toBuffer Method
  
.. _id3_document_document_image_to_buffer_class_method:

===============================================================================
DocumentImage.toBuffer Method
===============================================================================

Module: :ref:`DocumentImage<id3_document_document_image_class>`

Definition
----------

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.


.. tab-set::

    .. tab-item:: Python
      :sync: Python

      .. code:: Python

        to_buffer(self, document_image_format: ImageFormat, compression_level: float) -> bytearray

      **Parameters**

        .. line-block::

          ``document_image_format`` :ref:`ImageFormat<id3_document_image_format_enum>`
          :guilabel:`in` The image format to export the image to.

          ``compression_level`` float
          :guilabel:`in` The compression level to be applied.


      **Returns**

        .. line-block::

          ``bytearray``
          Buffer that receives the image data.

      **Exceptions**

        .. line-block::

          :ref:`DocumentException<id3_document_document_exception>`
          An error has occurred during Document Library execution.


    .. tab-item:: Dart
      :sync: Dart

      .. code:: Dart

        Uint8List toBuffer(ImageFormat documentImageFormat, double compressionLevel)

      **Parameters**

        .. line-block::

          ``documentImageFormat`` :ref:`ImageFormat<id3_document_image_format_enum>`
          :guilabel:`in` The image format to export the image to.

          ``compressionLevel`` double
          :guilabel:`in` The compression level to be applied.


      **Returns**

        .. line-block::

          ``Uint8List``
          Buffer that receives the image data.

      **Exceptions**

        .. line-block::

          :ref:`DocumentException<id3_document_document_exception>`
          An error has occurred during Document Library execution.


    .. tab-item:: C#
      :sync: C#

      .. code:: C#

        public byte[] ToBuffer(ImageFormat documentImageFormat, float compressionLevel)

      **Parameters**

        .. line-block::

          ``documentImageFormat`` :ref:`ImageFormat<id3_document_image_format_enum>`
          :guilabel:`in` The image format to export the image to.

          ``compressionLevel`` float
          :guilabel:`in` The compression level to be applied.


      **Returns**

        .. line-block::

          ``byte[]``
          Buffer that receives the image data.

      **Exceptions**

        .. line-block::

          :ref:`DocumentException<id3_document_document_exception>`
          An error has occurred during Document Library execution.


    .. tab-item:: Java
      :sync: Java

      .. code:: Java

        public byte[] toBuffer(ImageFormat documentImageFormat, float compressionLevel) throws DocumentException

      **Parameters**

        .. line-block::

          ``documentImageFormat`` :ref:`ImageFormat<id3_document_image_format_enum>`
          :guilabel:`in` The image format to export the image to.

          ``compressionLevel`` float
          :guilabel:`in` The compression level to be applied.


      **Returns**

        .. line-block::

          ``byte[]``
          Buffer that receives the image data.

      **Exceptions**

        .. line-block::

          :ref:`DocumentException<id3_document_document_exception>`
          An error has occurred during Document Library execution.


    .. tab-item:: Swift
      :sync: Swift

      .. code:: Swift

        public func toBuffer(documentImageFormat: ImageFormat, compressionLevel: Float) throws -> [UInt8]

      **Parameters**

        .. line-block::

          ``documentImageFormat`` :ref:`ImageFormat<id3_document_image_format_enum>`
          :guilabel:`in` The image format to export the image to.

          ``compressionLevel`` Float
          :guilabel:`in` The compression level to be applied.


      **Returns**

        .. line-block::

          ``[UInt8]``
          Buffer that receives the image data.

      **Exceptions**

        .. line-block::

          :ref:`DocumentException<id3_document_document_exception>`
          An error has occurred during Document Library execution.


    .. tab-item:: C
      :sync: C

      .. code:: C

        int id3DocumentImage_ToBuffer (
            ID3_DOCUMENT_IMAGE hDocumentImage, 
            id3DocumentImageFormat eDocumentImageFormat, 
            float compressionLevel, 
            unsigned char * data, 
            int * dataSize)

      **Parameters**

        .. line-block::

          ``hDocumentImage`` :ref:`ID3_DOCUMENT_IMAGE<id3_document_document_image_class>`
          :guilabel:`in` Handle to the DocumentImage object.

          ``eDocumentImageFormat`` :ref:`id3DocumentImageFormat<id3_document_image_format_enum>`
          :guilabel:`in` The image format to export the image to.

          ``compressionLevel`` float
          :guilabel:`in` The compression level to be applied.

          ``data`` unsigned char *
          :guilabel:`out` Buffer that receives the image data.

          ``dataSize`` int *
          :guilabel:`in` Size of the 'data' buffer. Receives the number of elements in the 'data' array.


      **Returns**

        .. line-block::

          ``int``
          An error code.
          See :ref:`id3DocumentError<id3_document_document_error_enum>` file for the list of possible error codes.


