Example: /Images/PNG/Write with PictureMBS

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

Platforms to show: All Mac Windows Linux Cross-Platform

/Images/PNG/Write with PictureMBS


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/Write with PictureMBS

This example is the version from Sun, 5th May 2018.

Project "Write with PictureMBS.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub Open() TestRGB TestGray End EventHandler
Sub TestGray() // Write a RGBA PNG file dim current as Picture = LogoMBS(500) // needs Main Plugin dim cpic as new PictureMBS(current) dim pic as new PictureMBS(current.Width, current.Height, PictureMBS.ImageFormatG) call pic.CopyPixels(cpic) // show in window window1.Backdrop = current // and write to file dim f as FolderItem = SpecialFolder.Desktop.Child("test gray.png") dim p as new PNGWriterMBS dim rows() as MemoryBlock dim h as integer = pic.Height-1 for i as integer = 0 to h rows.Append pic.RawRow(i) next p.Type = p.TypeGray p.Width = pic.Width p.bpc = 1 p.Rowbytes = pic.Width // one byte per pixel if p.OpenWriteDestination(f) then // open file if p.SetRows(rows) then // set picture to write if p.SetHeader(false, -1) then // setup file header if p.SetGamma(0) then // and default gamma if p.WriteInfo then // write file header if p.WriteRows then // write pixels if p.WriteEnd then // and write file end p = nil // cleanup f.Launch end if end if end if end if end if end if end if End Sub
Sub TestRGB() // Write a RGBA PNG file dim current as Picture = LogoMBS(500) // needs Main Plugin dim pic as new PictureMBS(current.Width, current.Height, PictureMBS.ImageFormatRGB) pic.DrawPictureRGB(current) // show in window window1.Backdrop = current // and write to file dim f as FolderItem = SpecialFolder.Desktop.Child("test rgb.png") dim p as new PNGWriterMBS dim rows() as MemoryBlock dim h as integer = pic.Height-1 for i as integer = 0 to h rows.Append pic.RawRow(i) next p.Type = p.TypeRGB p.Width = pic.Width p.bpc = 3 p.Rowbytes = pic.Width * 3 if p.OpenWriteDestination(f) then // open file if p.SetRows(rows) then // set picture to write if p.SetHeader(false, -1) then // setup file header if p.SetGamma(0) then // and default gamma if p.WriteInfo then // write file header if p.WriteRows then // write pixels if p.WriteEnd then // and write file end p = nil // cleanup f.Launch end if end if end if end if end if end if end if End Sub
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 Window1 Inherits Window
End Class
End Project

See also:

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


💬 Ask a question or report a problem