« Programming your own … | Home | MBS Xojo Plugins, ver… »

Reading JPEG Thumbnails from EXIF


For next MBS Xojo Plugins we add new methods to JPEGImporterMBS class to read thumbnail from EXIF data in a JPEG file. This allows you to very quickly get a thumbnail image. We support ScaleFactor property for some years now, which allows you to read a JPEG scaled down and get only the pixel data decompressed you need. We use this often for a preview. The time differences may be for a test image here: 5.6 milliseconds for the thumbnail at 160x120, 64 milliseconds for a preview at 504x378 and 276 milliseconds for full image at 4032x3024 pixels. So in your projects, if you need to show JPEGs quickly, you may first check for a thumbnail, then for a scaled down preview and only if user double click the entry load the whole picture.

Here some sample code:

Dim file As FolderItem = SpecialFolder.Desktop.Child("test.jpg") // first read header and check for thumbnail in EXIF Dim j As New JPEGImporterMBS j.file = file j.ReadExifData = True If j.ReadHeader Then Dim thumbnailData As String = j.ExifThumbnail If thumbnailData.LenB > 0 Then thumbnailPic = picture.FromData(thumbnailData) End If // now read a scaled down image Dim factor As Double = Min( j.Height / 300.0, j.Width / 300.0) If factor >= 8.0 Then j.ScaleFactor = 8 Elseif factor >= 4.0 Then j.ScaleFactor = 4 Else j.ScaleFactor = 2 End If j.Import Pic2 = j.Picture // finally read full image j.ScaleFactor = 0 j.Import Pic3 = j.Picture Else MsgBox j.ErrorMessage End If
Coming soon for MBS Plugins version 20.1pr5. See also CGImageSourceMBS class for MacOS to get quickly thumbnails for various image formats. The biggest plugin in space...
23 02 20 - 10:54