# toFile method

void toFile(

1. String? filepath,
2. double compressionLevel

)

Saves the image to the specified file. 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 filepath A string that contains the name of the file to which to save the image. param compressionLevel The compression level to be applied. throws DocumentException An error has occurred during Document Library execution.

## Implementation

    void toFile(String? filepath, double compressionLevel) {
      Pointer<Char>? pFilepath = filepath?.toNativeUtf8().cast<Char>();
      try {
        var err = documentSDK.id3DocumentImage_ToFile(_pHandle.value, pFilepath ?? nullptr, compressionLevel);
        if (err != DocumentError.success.value) {
          throw DocumentException(err);
        }
      } finally {
        if (pFilepath != null) {
          calloc.free(pFilepath);
        }
      }
    }