Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/Images/PNG/PNGOptimizer test
Required plugins for this example: MBS Images Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Images/PNG/PNGOptimizer test
This example is the version from Sun, 5th May 2018.
Project "PNGOptimizer test.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control list Inherits Listbox
ControlInstance list Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim fi,fo as FolderItem dim p as Picture p=LogoMBS(500) // needs Main Plugin fi=SpecialFolder.Desktop.Child("test unoptimized.png") if not fi.SaveAsPNGMBS(p,0) then MsgBox "Failed to save PNG file." Return end if fo=SpecialFolder.Desktop.Child("test optimized.png") fo.Delete // delete if existed before dim o as new MyPNGOptimizerMBS o.YieldTicks=10 // give time for other threads 'o.OptimizationLevel=2 // default is 2 o.InputFile=fi o.OutputFile=fo o.NoColorTypeReduction=true // für Beispiel // delete backup file if o.Optimize then list.AddRow "OK: Saved "+str(o.BytesSaved) o.OutputFile.Launch else list.AddRow "failed" end if End EventHandler
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyPNGOptimizerMBS Inherits PNGOptimizerMBS
EventHandler Sub Log(message as string) // you get messages in chunks where a chr(10) shows a new line dim a as integer = asc(Right(Message,1)) if a=10 or a=13 then Messages=Messages+left(Message,len(Message)-1) Messages=ReplaceLineEndings(Messages, EndOfLine.Macintosh) dim lines(-1) as string = split(Messages, EndOfLine.Macintosh) for each line as string in lines window1.list.AddRow "log: "+line next Messages="" else Messages=Messages+Message end if End EventHandler
EventHandler Sub Progress(index as integer, count as integer) if index<>window1.ProgressBar1.Value then window1.ProgressBar1.Value=index end if if count<>window1.ProgressBar1.Maximum then window1.ProgressBar1.Maximum=count end if End EventHandler
EventHandler Sub ProgressBegin() window1.ProgressBar1.Value=0 window1.ProgressBar1.Maximum=0 window1.ProgressBar1.Visible=true End EventHandler
EventHandler Sub ProgressEnd() window1.ProgressBar1.Value=0 window1.ProgressBar1.Maximum=0 window1.ProgressBar1.Visible=false End EventHandler
Property messages As string
End Class
Filetype image/png
End MyFileTypes
End Project

Feedback, Comments & Corrections

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

MBS Xojo tutorial videos