Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/QuickLook/QLThumbnailGenerator


Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS MacFrameworks Plugin

Last modified Fri, 2nd May 2024.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /MacFrameworks/QuickLook/QLThumbnailGenerator

Download this example: QLThumbnailGenerator.zip

Project "QLThumbnailGenerator.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Opening() Const path = "/System/Library/Desktop Pictures/Sonoma.heic" Var file As New FolderItem(path, FolderItem.PathModes.Native) Dim generator As New QLThumbnailGenerator Dim request As New QLThumbnailGenerationRequestMBS(file) generator.generateRepresentationsForRequest request // try again request = New QLThumbnailGenerationRequestMBS(file) request.iconMode = True generator.generateBestRepresentationForRequest(request) // and let make a jpeg file request = New QLThumbnailGenerationRequestMBS(file, 512, 512, QLThumbnailGenerationRequestMBS.RequestRepresentationTypeIcon) request.iconMode = True Dim dest As FolderItem = SpecialFolder.Desktop.Child("icon.png") generator.saveBestRepresentationForRequest(request, dest, "public.png") // and let make a jpeg file request = New QLThumbnailGenerationRequestMBS(file, 512, 512, QLThumbnailGenerationRequestMBS.RequestRepresentationTypeThumbnail) request.iconMode = False dest = SpecialFolder.Desktop.Child("preview.jpg") generator.saveBestRepresentationForRequest(request, dest, "public.jpeg") End EventHandler
End Class
Class PictureWindow Inherits DesktopWindow
Control Image Inherits DesktopImageViewer
ControlInstance Image Inherits DesktopImageViewer
End Control
Control ErrorLabel Inherits DesktopLabel
ControlInstance ErrorLabel Inherits DesktopLabel
End Control
Sub ShowFile(file as FolderItem, error as NSErrorMBS) If error <> Nil Then ErrorLabel.Text = error.LocalizedDescription End If If file <> Nil Then Dim pic As Picture = Picture.Open(file) image.Image = pic End If End Sub
Sub ShowResult(result as QLThumbnailRepresentationMBS, error as NSErrorMBS) If error <> Nil Then ErrorLabel.Text = error.LocalizedDescription End If If result <> Nil Then Dim pic As Picture = result.Picture image.Image = pic End If End Sub
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"
MenuItem HelpMenu = "&Help"
End MenuBar
Sign
End Sign
Class QLThumbnailGenerator Inherits QLThumbnailGeneratorMBS
EventHandler Sub generateBestRepresentationForRequestCompleted(request as QLThumbnailGenerationRequestMBS, thumbnail as QLThumbnailRepresentationMBS, error as NSErrorMBS) Dim pw As New PictureWindow pw.ShowResult thumbnail, error End EventHandler
EventHandler Sub generateRepresentationsForRequestUpdated(request as QLThumbnailGenerationRequestMBS, thumbnail as QLThumbnailRepresentationMBS, type as Integer, error as NSErrorMBS) Dim pw As New PictureWindow pw.ShowResult thumbnail, error Select Case type Case QLThumbnailRepresentationMBS.TypeIcon pw.Title = "Icon" Case QLThumbnailRepresentationMBS.TypeLowQualityThumbnail pw.Title = "LowQualityThumbnail" Case QLThumbnailRepresentationMBS.TypeThumbnail pw.Title = "Thumbnail" End Select End EventHandler
EventHandler Sub saveBestRepresentationForRequestCompleted(request as QLThumbnailGenerationRequestMBS, error as NSErrorMBS, file as FolderItem) Dim pw As New PictureWindow pw.ShowFile file, error pw.Title = "Saved image" End EventHandler
End Class
End Project

Download this example: QLThumbnailGenerator.zip

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


The biggest plugin in space...