.. index:: 
  !Image.toBuffer Method
  
.. _id3_face_image_to_buffer_class_method:

===============================================================================
Image.toBuffer Method
===============================================================================

Module: :ref:`Image<id3_face_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, image_format: ImageFormat, compression_level: float) -> bytearray

      **Parameters**

        .. line-block::

          ``image_format`` :ref:`ImageFormat<id3_face_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:`FaceException<id3_face_face_exception>`
          An error has occurred during Face Library execution.


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

      .. code:: Dart

        Uint8List toBuffer(ImageFormat imageFormat, double compressionLevel)

      **Parameters**

        .. line-block::

          ``imageFormat`` :ref:`ImageFormat<id3_face_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:`FaceException<id3_face_face_exception>`
          An error has occurred during Face Library execution.


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

      .. code:: C#

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

      **Parameters**

        .. line-block::

          ``imageFormat`` :ref:`ImageFormat<id3_face_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:`FaceException<id3_face_face_exception>`
          An error has occurred during Face Library execution.


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

      .. code:: Java

        public byte[] toBuffer(ImageFormat imageFormat, float compressionLevel) throws FaceException

      **Parameters**

        .. line-block::

          ``imageFormat`` :ref:`ImageFormat<id3_face_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:`FaceException<id3_face_face_exception>`
          An error has occurred during Face Library execution.


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

      .. code:: Swift

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

      **Parameters**

        .. line-block::

          ``imageFormat`` :ref:`ImageFormat<id3_face_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:`FaceException<id3_face_face_exception>`
          An error has occurred during Face Library execution.


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

      .. code:: C

        int id3FaceImage_ToBuffer (
            ID3_FACE_IMAGE hImage, 
            id3FaceImageFormat eImageFormat, 
            float compressionLevel, 
            unsigned char * data, 
            int * dataSize)

      **Parameters**

        .. line-block::

          ``hImage`` :ref:`ID3_FACE_IMAGE<id3_face_image_class>`
          :guilabel:`in` Handle to the Image object.

          ``eImageFormat`` :ref:`id3FaceImageFormat<id3_face_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:`id3FaceError<id3_face_face_error_enum>` file for the list of possible error codes.


