Table of contents

CImageIO

The CImageIO class handles image reading and writing (from/to files and memory).

Definition

Namespace: dynamsoft::utility

Assembly: DynamsoftUtility

class CImageIO

Methods

Method Description
ReadFromBase64String Reads an image from a base64 encoded string.
ReadFromFile Reads an image from a file.
ReadFromMemory Reads an image from a file in memory.
SaveToBase64String Saves an image to a base64 encoded string.
SaveToFile Saves an image to a file.
SaveToMemory Saves an image to a file in memory.

ReadFromBase64String

Reads an image from a base64 encoded string.

CImageData* ReadFromBase64String(const char* base64String, int* errorCode = NULL);

Parameters

[in] base64String A base64 encoded string that represents an image.

[out] errorCode The error code.

Return value

Returns a pointer to a CImageData object representing the image if succeeds, nullptr otherwise.

Remarks

If the file format is gif, pdf or tiff, we read the first page of the image file. The caller is responsible for freeing the memory allocated for the image.

See Also

CImageData

ReadFromFile

Reads an image from a file.

CImageData* ReadFromFile(const char* filePath, int* pErrorCode = NULL)

Parameters

[in] filePath The path of the image file.

[out] pErrorCode The The error code.

Return value

Returns a pointer to a CImageData object representing the image if succeeds, nullptr otherwise.

Remarks

If the file format is gif, pdf or tiff, we read the first page of the image file. The caller is responsible for freeing the memory allocated for the image.

See Also

CImageData

ReadFromMemory

Reads an image from a file in memory.

CImageData* ReadFromMemory(const unsigned char* imageFileBytes, int imageFileBytesLength, int* pErrorCode = NULL)

Parameters

[in] imageFileBytes An array of unsigned char representing the image file in memory.

[in] imageFileBytesLength The length of the image file in bytes.

[out] pErrorCode The The error code.

Return value

Returns a pointer to a CImageData object representing the image if succeeds, nullptr otherwise.

Remarks

If the file format is gif, pdf or tiff, we read the first page of the image file. The caller is responsible for freeing the memory allocated for the image.

See Also

CImageData

SaveToBase64String

Saves an image to a base64 encoded string.

int SaveToBase64String(const CImageData* imageData, ImageFileFormat imageFormat, char** base64String);

Parameters

[in] imageData A pointer to the image data to be saved.

[in] imageFormat The image file format to be saved.

[in] base64String A base64 encoded string that represents an image. The string is allocated by the SDK and must be freed by calling CCoreModule::FreeBytes.

Return value

Returns an integer indicating the success of the operation. 0 indicates success, while a non-zero value indicates an error occurred.

Error Code Value Description
EC_NULL_POINTER -10002 The ImageData object is null.
EC_IMGAE_DATA_INVALID -10069 The input ImageData object contains invalid parameter(s).

See Also

CImageData

ImageFileFormat

SaveToFile

Saves an image to a file.

int SaveToFile(const CImageData *pImageData, const char *path, bool overwrite = true)

Parameters

[in] pImageData A pointer to the image data to be saved.

[in] path The targeting file path with the file name and extension name.

[in] overwrite A flag indicating whether to overwrite the file if it already exists. Defaults to true.

Return value

Returns an integer indicating the success of the operation. 0 indicates success, while a non-zero value indicates an error occurred.

Error Code Value Description
EC_NULL_POINTER -10002 The ImageData object is null.
EC_FILE_TYPE_NOT_SUPPORTED -10006 The file type is not supported.
EC_FILE_ALREADY_EXISTS -10067 The file already exists but overwriting is disabled.
EC_CREATE_FILE_FAILED -10068 The file path does not exist but cannot be created, or the file cannot be created for any other reason.
EC_IMGAE_DATA_INVALID -10069 The input ImageData object contains invalid parameter(s).

See Also

CImageData

SaveToMemory

Saves an image to a file in memory.

int SaveToMemory(const CImageData* pImageData, ImageFileFormat imageFormat, unsigned char** imageFileBytes, int* imageFileBytesLength)

Parameters

[in] pImageData A pointer to the image data to be saved.

[in] imageFormat The image file format to be saved.

[out] imageFileBytes An array of unsigned char representing the image file in memory.

[out] imageFileBytesLength The length of the image file in bytes.

Return value

Returns an integer indicating the success of the operation. 0 indicates success, while a non-zero value indicates an error occurred.

Error Code Value Description
EC_NULL_POINTER -10002 The ImageData object is null.
EC_IMGAE_DATA_INVALID -10069 The input ImageData object contains invalid parameter(s).

See Also

CImageData

ImageFileFormat

This page is compatible for:

Is this page helpful?

YesYes NoNo

In this article: