Provides extraction and conversion capabilities for images embedded in Machine-Readable Travel Documents (MRTDs)
This class provides convenience functions for extracting and converting MRTD image data to suitable formats for display or processing. It may be used in conjunction with MRTD_Listener.readCompleteEvent to retrieve images from MRTDs.
Thread safety:
Public Member Functions | |
MRTD_Image () | |
Default constructor - empty (null) image. | |
MRTD_Image (@NonNull BER_TLV data) | |
Constructor - extracts MRTD image data from a BER-TLV structure. More... | |
MRTD_Image (@NonNull byte[] data, long offset) | |
Constructor - extracts MRTD image data from a byte array. More... | |
byte [] | data () |
Image data, passed by copy More... | |
byte [] | decodeJPEG2000 () |
Decode the JPEG 2000 content, if any, to the Microsoft BMP (DIB) format. More... | |
String | encodeAsBase64 () |
Generate a MIME-compliant Base64 encoding of the image data. More... | |
boolean | JPEG2000 () |
Was a JPEG 2000 data block successfully extracted at construction? More... | |
boolean | valid () |
Was a data block successfully extracted at construction? More... | |
MRTD_Image | ( | @NonNull BER_TLV | data | ) |
Constructor - extracts MRTD image data from a BER-TLV structure.
The constructor scans the supplied BER-TLV object for a primitive data field with tag #46, and containing JPEG or JPEG2000 preambles. The first such data block will be stored inside the constructed object; if no such block is found, then the object will hold no data.
Note that the contents of the data will not be validated beyond checking whether the preambles are present.
data | BER-TLV data read from an MRTD, typically taken from a MRTD_Listener callback |
MRTD_Image | ( | @NonNull byte [] | data, |
long | offset | ||
) |
Constructor - extracts MRTD image data from a byte array.
The constructor scans the supplied data for a JPEG or JPEG2000 preamble, providing a valid offset is supplied. The first such data block will be stored inside the constructed object; if no such block is found, or if the supplied offset is out of range for the supplied data, then the constructed object will hold no data.
data | Collection of data from which the image is to be read |
offset | If non-zero, scanning for data block commences at the specified offset rather than the beginning of the array; typically set to zero. Valid range 0 to data.length-1 (inclusive). |
byte [] data | ( | ) |
Image data, passed by copy
byte [] decodeJPEG2000 | ( | ) |
Decode the JPEG 2000 content, if any, to the Microsoft BMP (DIB) format.
String encodeAsBase64 | ( | ) |
Generate a MIME-compliant Base64 encoding of the image data.
If the supplied data is in JPEG (JFIF) format, then it will be encoded in Base64 without any prior conversion. If the supplied image is in JPEG 2000 format, then it will be converted to BMP (DIB) format prior to Base64 encoding. If the supplied data is invalid, or in any other format, then an empty string will be returned.
boolean JPEG2000 | ( | ) |
Was a JPEG 2000 data block successfully extracted at construction?
boolean valid | ( | ) |
Was a data block successfully extracted at construction?