Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacCG Plugin, MBS MacFrameworks Plugin, MBS MacCF Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacOSX/Image Thumbnail
This example is the version from Mon, 5th May 2019.
Project "Image Thumbnail.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect)
if pic <> nil then
// Calculate scale factor
dim faktor as Double = min( g.Height / Pic.Height, g.Width / Pic.Width)
// Calculate new size
dim w as integer = Pic.Width * faktor
dim h as integer = Pic.Height * faktor
// create new picture
// draw picture in the new size
g.DrawPicture Pic, 0, 0, w, h, 0, 0, Pic.Width, Pic.Height
end if
End EventHandler
End Control
Control ButtonQuickLook Inherits PushButton
ControlInstance ButtonQuickLook Inherits PushButton
EventHandler Sub Action()
#if TargetMacOS then
dim f as FolderItem = GetOpenFolderItem(FileTypes1.ImageTiff)
if f = nil then Return
dim t as Double = Microseconds
pic = f.QuickLookMBS(500, 500)
dim d as Double = Microseconds - t
LabelQuickLook.Text = Format(d / 1000000.0, "0.000")+" seconds"
canvas1.Invalidate
#else
MsgBox "Mac only"
#endif
End EventHandler
End Control
Control LabelQuickLook Inherits Label
ControlInstance LabelQuickLook Inherits Label
End Control
Control ButtonImageSource Inherits PushButton
ControlInstance ButtonImageSource Inherits PushButton
EventHandler Sub Action()
#if TargetMacOS then
dim f as FolderItem = GetOpenFolderItem(FileTypes1.ImageTiff)
if f = nil then Return
dim t as Double = Microseconds
// our options for thumbnail creation
dim o as new Dictionary
o.Value(CGImageSourceMBS.kCGImageSourceThumbnailMaxPixelSize) = 500
o.Value(CGImageSourceMBS.kCGImageSourceCreateThumbnailFromImageIfAbsent) = true
// open file
dim c as new CGImageSourceMBS(f)
// create thumbnail
dim i as CGImageMBS = c.CreateThumbnailAtIndex(0, o)
if i <> nil then
pic = i.Picture
else
pic = nil
end if
dim d as Double = Microseconds - t
LabelImageSource.Text = Format(d / 1000000.0, "0.000")+" seconds"
canvas1.Invalidate
#else
MsgBox "Mac only"
#endif
End EventHandler
End Control
Control LabelImageSource Inherits Label
ControlInstance LabelImageSource Inherits Label
End Control
Property pic As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
FileTypes1
Filetype image/tiff
End FileTypes1
End Project
See also:
The items on this page are in the following plugins: MBS MacOSX Plugin.