Platforms to show: All Mac Windows Linux Cross-Platform

/Images/PNG/PNG Test/PNG Test with Options


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/PNG/PNG Test/PNG Test with Options

This example is the version from Sun, 10th Dec 2016.

Project "PNG Test with Options.xojo_binary_project"
FileTypes
Filetype image/png
End FileTypes
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control Canvas2 Inherits Canvas
ControlInstance Canvas2 Inherits Canvas
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Dim p As Picture Dim f As FolderItem Dim s As String Dim success As Boolean s = "test.png" // Comp the two images together for the hell of it p = new Picture(Canvas1.Backdrop.Width, Canvas1.Backdrop.Height, 32) p.Graphics.DrawPicture (Canvas1.Backdrop, 0, 0, p.Width, p.Height) p.Graphics.DrawPicture (Canvas2.Backdrop, 0, 0, p.Width, p.Height) // Draw in a cheap mask for testing if CheckBox1.Value then s = "test with mask.png" p.Mask.Graphics.ForeColor = &cFFFFFF p.Mask.Graphics.FillRect ( 0, 0, p.Width, p.Height ) p.Mask.Graphics.ForeColor = &c000000 p.Mask.Graphics.FillOval ( 0, 0, p.Width, p.Height ) end if // Save it f = GetSaveFolderItem( "image/png", s ) if f <> Nil then success = f.SaveAsPNGMBS(p, 0.0, CheckBox2.Value, PopupMenu1.RowTag(PopupMenu1.ListIndex)) if NOT success then MsgBox "Save Failed!" end if end if End EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() test End EventHandler
End Control
Control CheckBox2 Inherits CheckBox
ControlInstance CheckBox2 Inherits CheckBox
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
EventHandler Sub Open() const PNG_NO_FILTERS=0 const PNG_FILTER_NONE=8 const PNG_FILTER_SUB=16 const PNG_FILTER_UP=32 const PNG_FILTER_AVG=64 const PNG_FILTER_PAETH=128 me.DeleteAllRows me.AddRow "No filters" me.RowTag(0)=PNG_NO_FILTERS me.AddRow "Filter: None" me.RowTag(1)=PNG_FILTER_NONE me.AddRow "Filter: Sub" me.RowTag(2)=PNG_FILTER_SUB me.AddRow "Filter: Up" me.RowTag(3)=PNG_FILTER_UP me.AddRow "Filter: Average" me.RowTag(4)=PNG_FILTER_AVG me.AddRow "Filter: Paeth" me.RowTag(5)=PNG_FILTER_PAETH me.AddRow "Filter: All" me.RowTag(6)=PNG_FILTER_NONE + PNG_FILTER_SUB + PNG_FILTER_UP + PNG_FILTER_AVG + PNG_FILTER_PAETH me.ListIndex=0 End EventHandler
End Control
EventHandler Sub Open() dim f as FolderItem dim p as PNGPictureMBS f=FindFile("arches.png") p=f.OpenAsPNGMBS(0) if p<>nil then Canvas1.Backdrop = p.CombinePictureWithMask end if f=FindFile("radio.png") p=f.OpenAsPNGMBS(0) if p<>Nil then Canvas2.Backdrop = p.CombinePictureWithMask end if End EventHandler
Function FindFile(name as string) As FolderItem // Look for file in parent folders from executable on dim parent as FolderItem = app.ExecutableFile.Parent while parent<>Nil dim file as FolderItem = parent.Child(name) if file<>Nil and file.Exists then Return file end if parent = parent.Parent wend End Function
Protected Sub test() dim s1,s2 as string s1=PictureToPNGStringMBS(Canvas1.Backdrop,0, CheckBox2.Value, PopupMenu1.RowTag(PopupMenu1.ListIndex)) s2=PictureToPNGStringMBS(Canvas2.Backdrop,0, CheckBox2.Value, PopupMenu1.RowTag(PopupMenu1.ListIndex)) MsgBox str(lenb(s1))+" bytes for left image and "+str(lenb(s2))+" bytes for right image." Canvas1.Backdrop=nil Canvas2.Backdrop=nil Canvas2.Backdrop=PNGStringToPictureMBS(s1,0) Canvas1.Backdrop=PNGStringToPictureMBS(s2,0) End Sub
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

See also:

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


The biggest plugin in space...