You find this example project in your Plugins Download as a Xojo project file within the examples folder: /GraphicsMagick/GraphicsMagick/GraphicsMagick threaded convert
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean
if column = 0 then
dim Pic as picture = me.CellTag(row, column)
if pic <> nil then
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
dim xx as integer = (g.Width - w) / 2
dim yy as integer = (g.Height - h) / 2
g.DrawPicture Pic, xx, yy, w, h, 0, 0, pic.Width, pic.Height
end if
end if
End EventHandler
End Control
Control EndTimer Inherits Timer
ControlInstance EndTimer Inherits Timer
EventHandler Sub Action()
// have newer images?
for i as integer = list.ListCount to thread.Images.Ubound
dim file as folderitem = thread.files(i)
dim image as GMImageMBS = thread.Images(i)
dim pic as Picture = image.copyPicture
List.AddRow " ", file.DisplayName+EndOfLine+str(file.Length/1024,"0")+" KB"
list.CellTag(List.LastIndex, 0) = pic
next
if thread.done then
MsgBox "Done after "+str( (thread.EndTime-thread.StartTime) / 1000000.0, "0.0")+" seconds."
me.Mode = timer.ModeOff
thread = nil
end if
End EventHandler
End Control
EventHandler Sub Open()
dim f as FolderItem = GetFolderItem("Test Files")
if not f.Exists then
break // no test files?
return
end if
thread = new MyThread
thread.folder = f
thread.run
End EventHandler
Property thread As MyThread
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
Class MyThread Inherits Thread
EventHandler Sub Run()
dim c as integer = folder.count
dim filesTodo() as FolderItem
for i as integer = 1 to c
dim file as FolderItem = folder.TrueItem(i)
if file <> nil and file.Visible then
// skip jpeg?
'if file.Name.Right(4) = ".jpg" then continue
filesTodo.Append file
end if
next
StartTime = Microseconds
for each file as FolderItem in filesTodo
dim converter as new GMConvertMBS
converter.InputFile = file
dim ScaleGeometry as new GMGeometryMBS(512,512)
ScaleGeometry.aspect = false // keep aspect
ScaleGeometry.greater = true // Resize if image is greater than size (>)
// Thumbnail scale is faster, but normal scale is better quality
'converter.ThumbnailGeometry = ScaleGeometry
converter.ScaleGeometry = ScaleGeometry
converter.Trim = true
converter.AutoOrient = true
converter.Strip = true // remove metadata
converter.OutputMagick = "jpeg"
converter.OutputFile = folder.Child(file.Name+".jpg")
converter.Quality = 90 // JPEG quality
converter.run
if converter.OutputImage <> nil then
self.images.Append converter.OutputImage
self.files.append file
end if
next
EndTime = Microseconds
done = true
End EventHandler
Property EndTime As Double
Property Images() As GMImageMBS
Property StartTime As Double
Property done As Boolean
Property files() As FolderItem
Property folder As FolderItem
End Class