fun hasJpgThumbnail(): Boolean { if (getThumbnailType() !== ExifDirectory.COMPRESSION_JPEG) return false val thumbData: ByteArray thumbData = try { val exif: ExifDirectory = metadata.getDirectory(ExifDirectory::class.java) as ExifDirectory exif.getThumbnailData() } catch (e: MetadataException) { return false } if (thumbData.size > 2) { var magicNumber: Int magicNumber = thumbData[0] and 0xFF shl 8 magicNumber = magicNumber or (thumbData[1] and 0xFF) if (magicNumber == ImageMetadataReader.JPEG_FILE_MAGIC_NUMBER) return true } return false }
Performs checks to determine if the image has a JPG thumbnail in the EXIF data . < p > The EXIF TAG_COMPRESION , and the magic number at the beginning of the thumbnail bytes are used to verify that the thumb is in JPG format