Platforms to show: All Mac Windows Linux Cross-Platform

/Images/JPEG/Quick JPEG Preview


Required plugins for this example: MBS Images Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/JPEG/Quick JPEG Preview

This example is the version from Sun, 9th May 2020.

Project "Quick JPEG Preview.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If pic1 <> Nil Then Dim faktor As Double = Min( g.Height / Pic1.Height, g.Width / Pic1.Width) // Calculate new size Dim w As Integer = Pic1.Width * faktor Dim h As Integer = Pic1.Height * faktor g.DrawPicture Pic1, 0, 0, w, h, 0, 0, Pic1.Width, pic1.Height End If End EventHandler
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If Pic2 <> Nil Then Dim faktor As Double = Min( g.Height / Pic2.Height, g.Width / Pic2.Width) // Calculate new size Dim w As Integer = Pic2.Width * faktor Dim h As Integer = Pic2.Height * faktor g.DrawPicture Pic2, 0, 0, w, h, 0, 0, Pic2.Width, Pic2.Height End If End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Canvas3 Inherits Canvas
ControlInstance Canvas3 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If Pic3 <> Nil Then Dim faktor As Double = Min( g.Height / Pic3.Height, g.Width / Pic3.Width) // Calculate new size Dim w As Integer = Pic3.Width * faktor Dim h As Integer = Pic3.Height * faktor g.DrawPicture Pic3, 0, 0, w, h, 0, 0, Pic3.Width, Pic3.Height End If End EventHandler
End Control
Control Label3 Inherits Label
ControlInstance Label3 Inherits Label
End Control
Control Info1 Inherits Label
ControlInstance Info1 Inherits Label
End Control
Control Info2 Inherits Label
ControlInstance Info2 Inherits Label
End Control
Control Info3 Inherits Label
ControlInstance Info3 Inherits Label
End Control
EventHandler Sub Open() Dim file As FolderItem = SpecialFolder.Desktop.Child("test.jpg") If file = Nil Or Not file.Exists Then // pick file file = GetOpenFolderItem(FileTypes1.Jpeg) If file = Nil Then Quit end if End If Dim m1 As Double = Microseconds // 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 m2 As Double = Microseconds Dim thumbnailData As String = j.ExifThumbnail Dim thumbnailPic As Picture = Nil If thumbnailData.LenB > 0 Then thumbnailPic = picture.FromData(thumbnailData) End If Dim m3 As Double = Microseconds If thumbnailPic <> Nil Then Pic1 = thumbnailPic label1.Text = Str( (m3-m1) / 1000.0, "0.0")+" ms for thumbnail" Info1.Text = Str(pic1.Width)+"x"+Str(pic1.Height) canvas1.Invalidate Else label1.Text = "no thumbnail" Info1.Text = "" 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 Dim m4 As Double = Microseconds Pic2 = j.Picture Dim d1 As Double = m2-m1 // init time Dim d2 As Double = m4-m3 // time for reading jpeg If Pic2 = Nil Then label2.Text = "no preview" Info2.Text = "" Else label2.Text = Str( (d1+d2) / 1000.0, "0.0")+" ms for preview" Info2.Text = Str(pic2.Width)+"x"+Str(pic2.Height) canvas2.Invalidate End If // finally read full image Dim m5 As Double = Microseconds j.ScaleFactor = 0 j.ReadExifData = true j.Import Dim m6 As Double = Microseconds Pic3 = j.Picture Dim d3 As Double = m6-m5 // time for reading jpeg If Pic3 = Nil Then label3.Text = "no picture" Info3.Text = "" Else label3.Text = Str( (d1+d3) / 1000.0, "0.0")+" ms for full picture" Info3.Text = Str(pic3.Width)+"x"+Str(pic3.Height) canvas3.Invalidate End If Title = Title+", Orientation: " + Str(j.ExifOrientation) Else MsgBox j.ErrorMessage End If End EventHandler
Property Pic1 As Picture
Property Pic2 As Picture
Property Pic3 As Picture
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
FileTypes1
Filetype image/jpeg
End FileTypes1
End Project

The items on this page are in the following plugins: MBS Images Plugin.


The biggest plugin in space...