Image Formats NG
Public Member Functions | Static Public Member Functions | List of all members
ImageIO Class Reference

Basic Image unput/output. More...

Public Member Functions

 ImageIO ()
 Creates an ImageIO object.
 
 ImageIO (const QString &fileName, const QMimeType &mimeType=QMimeType())
 Creates an ImageIO object with the given fileName and mimeType.
 
 ImageIO (QIODevice *device, const QMimeType &mimeType=QMimeType())
 Creates an ImageIO object with the given device and mimeType.
 
 ImageIO (const QString &fileName, const QString &mimeType)
 Creates an ImageIO object with the given fileName and mimeType.
 
 ImageIO (QIODevice *device, const QString &mimeType)
 Creates an ImageIO object with the given device and mimeType.
 
 ~ImageIO ()
 Destroys ImageIO object.
 
QString fileName () const
 This property holds the filename that is set to this ImageIO object.
 
QIODevice * device () const
 This property holds the device that is set to this ImageIO object.
 
QMimeType mimeType () const
 This property holds the mime type that is set to this ImageIO object. More...
 
QByteArray subType () const
 This property holds the sub type that is set to this ImageIO object. More...
 
std::pair< ImageIOResult, ImageHeaderreadHeader ()
 Reads the header of an image. More...
 
std::pair< ImageIOResult, ImageContentsreadContents (const ImageHeader &header, const ImageOptions &options=ImageOptions())
 Reads the contents of an image. More...
 
std::pair< ImageIOResult, ImageContentsread (const ImageOptions &options=ImageOptions())
 Reads both header and contents of an image. More...
 
ImageIOResult write (const ImageContents &contents, const ImageOptions &options=ImageOptions())
 Writes the given contents with the given options to the device. More...
 
bool supportsOption (ImageOptions::Option option, const QByteArray &subType=QByteArray()) const
 Returns true if current format supports the given option for the given subType, otherwise returns false. More...
 

Static Public Member Functions

static QVector< ImageFormatInfosupportedImageFormats (ImageFormatInfo::Capabilities caps=ImageFormatInfo::ReadWrite)
 Returns the list of supported image format for the given caps.
 
static Optional< ImageFormatInfoimageFormat (const QMimeType &mimeType)
 Returns information about format with the given mimeType.
 
static Optional< ImageFormatInfoimageFormat (const QString &mimeTypeName)
 Returns information about format with the given mimeTypeName.
 

Detailed Description

Basic Image unput/output.

This class is used for a customised image reading/writing.

Member Function Documentation

◆ mimeType()

QMimeType ImageIO::mimeType ( ) const

This property holds the mime type that is set to this ImageIO object.

If no mime type is set, it is automatically determined from the device contents before reading.

◆ read()

std::pair< ImageIOResult, ImageContents > ImageIO::read ( const ImageOptions options = ImageOptions())

Reads both header and contents of an image.

Returns the status of the operation as an ImageIOResult. Empty ImageContents is returned in case of an error.

This is the easiest way to read an image. This can be done as following:

ImageIO reader("image.png");
auto result = reader.read();
ImageIOResult ok = result.first;
if (!ok) {
qWarning() << "Error reading image:" << ok.toString();
return 1;
}
ImageContents contents = result.second;
handleHeader(contents.header());
handleImage(contents.image());

Reading can be customised by passing ImageOptions:

ImageIO reader("image.dds");
ImageOptions options;
options.setScaledSize(QSize(64, 64));
options.setSkipMipmaps(true);
auto result = reader.read(options);
// ...

◆ readContents()

std::pair< ImageIOResult, ImageContents > ImageIO::readContents ( const ImageHeader header,
const ImageOptions options = ImageOptions() 
)

Reads the contents of an image.

This method should be called after readHeader(). If you don't need to read image header and contents separately, use read() instead.

Returns the status of the operation as an ImageIOResult. Empty ImageContents is returned in case of an error.

See also
readHeader(), read()

◆ readHeader()

std::pair< ImageIOResult, ImageHeader > ImageIO::readHeader ( )

Reads the header of an image.

This method can be used to determine common imaпe meta information (size, image format, etc) without reading image data itself.

Returns the status of the operation as an ImageIOResult. Empty ImageHeader is returned in case of an error.

After reading header, you should call readContents() function to retreive actual image data.

Typical usage is following:

ImageIO reader("image.png");
const auto headerResult = reader.readHeader();
if (!headerResult.first) {
qWarning() << "Error reading header:" << headerResult.first.toString();
return 1;
}
ImageHeader header = headerResult.second;
handleHeader(header);
const auto contentsResult = reader.readContents(header);
if (!contentsResult.first) {
qWarning() << "Error reading header:" << headerResult.first.toString();
return 1;
}
ImageContents contents = contentsResult.second;
handleImage(contents.image());
See also
readContents(), read()

◆ subType()

QByteArray ImageIO::subType ( ) const

This property holds the sub type that is set to this ImageIO object.

Sub type is used for writing to configure the type of the resulting image file.

◆ supportsOption()

bool ImageIO::supportsOption ( ImageOptions::Option  option,
const QByteArray &  subType = QByteArray() 
) const

Returns true if current format supports the given option for the given subType, otherwise returns false.

Current format is the format specified by the ImageIO::mimeType.

◆ write()

ImageIOResult ImageIO::write ( const ImageContents contents,
const ImageOptions options = ImageOptions() 
)

Writes the given contents with the given options to the device.

Returns the status of the operation.