Platforms to show: All Mac Windows Linux Cross-Platform

/Images/LargePicture/PNG Load and Save


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/LargePicture/PNG Load and Save

This example is the version from Sun, 17th Mar 2012.

Project "PNG Load and Save.xojo_binary_project"
FileTypes
Filetype image/png
End FileTypes
Class Window1 Inherits Window
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim p as Picture p=LogoMBS(500) current=new PictureMBS(p) run End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim p as Picture dim q as PictureMBS p=LogoMBS(500) q=new PictureMBS(p) current=new PictureMBS(p.Width, p.Height, picturembs.ImageFormatG) call Current.CopyPixels(q) run End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() SavePNG End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action() OpenPNG End EventHandler
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action() Current=nil run End EventHandler
End Control
Sub OpenPNG() dim f as FolderItem f=GetopenFolderItem(FileTypes.Png) if f<>Nil then Current=nil dim p as new PNGReaderMBS if p.OpenFile(f) then if p.ApplyOptions(0) then Current=new PictureMBS(p.Width,p.Height,PictureMBS.ImageFormatRGB) dim i,c as integer c=p.Height-1 for i=0 to c Current.RowInFormat(i, PictureMBS.ImageFormatRGBA)=p.ReadRow() next end if end if run end if End Sub
Protected Sub SavePNG() dim f as FolderItem f=GetsaveFolderItem(FileTypes.Png,"test.png") if f<>Nil then const PNG_COLOR_MASK_PALETTE = 1 const PNG_COLOR_MASK_COLOR = 2 const PNG_COLOR_MASK_ALPHA = 4 dim p as new PNGWriterMBS p.Width=Current.Width p.Height=Current.Height p.Type=PNG_COLOR_MASK_COLOR p.bpc=3 p.Rowbytes=p.Width*p.bpc if p.OpenWriteDestination(f) then if p.SetHeader(false, -1) then if p.SetGamma(0) then if p.WriteInfo then dim i,c as integer c=p.Height-1 for i=0 to c p.WriteRow current.RowInFormat(i, Current.ImageFormatRGB) next if p.WriteEnd then MsgBox "OK" end if end if end if end if end if end if End Sub
Protected Sub run() if Current=nil then canvas1.Backdrop=nil else Canvas1.Backdrop=current.CopyPicture end if End Sub
Property Protected current As PictureMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

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


The biggest plugin in space...