scantools  1.0.4
Graphics manipulation with a view towards scanned documents
Public Member Functions | List of all members
TIFFReader Class Reference

Reads TIFF files and converts them to QImages. More...

#include <TIFFReader.h>

Public Member Functions

 TIFFReader (const QString &fileName)
 Constructs a TIFF document from a file. More...
 
 ~TIFFReader ()
 Standard destructor.
 
bool hasError ()
 Error status. More...
 
QString error ()
 Error message. More...
 
quint32 size ()
 Number of images in the TIFF document. More...
 
QImage operator[] (quint16 pageNumber)
 Read image. More...
 

Detailed Description

Reads TIFF files and converts them to QImages.

This class reads TIFF files into QImages. The class exist because the QImageReader that is shipped with Qt does not handle multi-page TIFF files.

// Minimal example
// Read the 5th page from a TIFF document
TIFFReader doc("filename.tiff");
QImage fifthPage = doc[4]; // Page numbering starts at zero
Reads TIFF files and converts them to QImages.
Definition: TIFFReader.h:49

The methods of this class are reentrant and thread safe. The implementation ensures that only one thread can access the document at any given time. This class does not use libtiff directly, which is extremely hard to use in a thread-safe manner. It does use, however, Qt's TIFF reader.

Definition at line 48 of file TIFFReader.h.

Constructor & Destructor Documentation

◆ TIFFReader()

TIFFReader::TIFFReader ( const QString &  fileName)
explicit

Constructs a TIFF document from a file.

Once the TIFFReader is constructed, the error status should be checked using the method hasError().

Parameters
fileNameName of the TIFF file
Warning
This method makes a private copy of the TIFF file as a temporary file. This might be a concern if the TIFF file is extremely large (e.g. several GB).

Member Function Documentation

◆ error()

QString TIFFReader::error ( )

Error message.

In case that hasError() returns 'true', this method returns a human-readable description of the error.

Returns
Human-readable description of the error

◆ hasError()

bool TIFFReader::hasError ( )

Error status.

Returns
True iff an error has occurred

◆ operator[]()

QImage TIFFReader::operator[] ( quint16  pageNumber)

Read image.

This method reads the n.th image of the TIFF file and returns it as a QImage. In case of error, an empty image is returned and an error condition is set.

Parameters
pageNumberPage number
Returns
Image, or an empty image in case of error
Warning
This method must not be used if an error conditions is set.

◆ size()

quint32 TIFFReader::size ( )

Number of images in the TIFF document.

Returns
Number of images
Warning
This method must not be used if an error conditions is set.

The documentation for this class was generated from the following file: