PNG Utilities Plugin - Method Reference Index
NOTE: PNG gamma is an often misunderstood and misused feature of the format. In order to avoid gamma correction entirely, simply pass a value of -1.0 to any method that takes an optional gamma parameter. The notes below describe how gamma is applied when importing vs. exporting PNG data.

OpenAs/GetPicture methods:
Using a gamma value of -1.0 will return raw RGB pixels. Omitting the gamma parameter will attempt to use the file embedded gamma, or apply system corrected gamma if no embedded value is found. Any positive gamma value will adjust the resulting Picture's gamma to that setting. Note that index-coloured PNG files will be expanded to a full 32 bits when converted to an RB Picture object. The Picture.HasMask extension can be used in conjunction with the OpenAs/GetPictureWithMask methods to determine whether a PNG file contains transparency information.

SavePicture/GetData methods:
Using a gamma value of -1.0 will create a PNG without an embedded gAMA chunk. Omitting the gamma parameter will result in the current system gamma being embedded. Any positive gamma values are be embedded as-is.

PNGu.OpenAsPicture(file As FolderItem, [gamma As Single]) As Picture
Returns a Picture containing the RGB portion of a PNG file. Alpha channels are ignored if present. Returns Nil if the file is not a valid PNG, or if an error was encountered while loading.

PNGu.GetPicture(data As String, [gamma As Single]) As Picture
Returns a Picture containing the RGB portion of the PNG data contained in a string. Alpha channels are ignored if present. This function is useful to retrieve PNG images from within virtual volumes, databases, or any other custom data container. Returns Nil if the data is not a valid PNG, or if an error was encountered while creating the picture.

PNGu.OpenAsPictureWithMask(file As FolderItem, [gamma As Single]) As Picture
Returns a Picture containing the RGB portion of a PNG file, and the PNG's alpha information (if present). The alpha channel is inverted and drawn into the Picture's mask property. Returns Nil if the file is not a valid PNG, or if an error was encountered while loading.

PNGu.GetPictureWithMask(data As String, [gamma As Single]) As Picture
Returns a Picture containing the RGB portion of the PNG data contained in a string, and the PNG's alpha information (if present). The alpha channel is inverted and drawn into the Picture's mask property. This function is useful to retrieve PNG images from within virtual volumes, databases, or any other custom data container. Returns Nil if the data is not a valid PNG, or if an error was encountered while creating the picture.

PNGu.SavePicture(file As FolderItem, image As Picture, [gamma As Single]) As Boolean
Saves a Picture as a 24bit RGB PNG, or a 32bit RGBA PNG if the picture contains a mask. Returns True if successful.

PNGu.GetData(image As Picture, [gamma As Single]) As String
Returns a string containing raw binary PNG data. The data will either be 24bit RGB, or 32bit RGBA if the picture contains a mask. This function is useful to store PNG images within virtual volumes, databases, or any other custom data container. Returns a nil string if an error occurs while writing the data.

Picture.HasMask As Boolean
A read-only property that reports whether a Picture object has a non-nil mask. This extension is needed since accessing the Picture.Mask property within REALbasic actually creates the Mask object. E.g. the expression: p.Mask = Nil is always false. Also note that due to this behaviour you may get false positives in the REALbasic debugger when viewing a Picture's properties.

Index