Platforms to show: All Mac Windows Linux Cross-Platform

Back to PNGWriterMBS class.

PNGWriterMBS.CloseDestination

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Closes the file.

PNGWriterMBS.Finish as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finishes the PNG file and returns the PNG file content as string.

Returns "" on any error.

PNGWriterMBS.OpenWriteDestination(file as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Opens the file to write.
Example
Dim f As FolderItem = SpecialFolder.Desktop.Child("test.png")
Dim p As New PNGWriterMBS
Dim pic As Picture = LogoMBS(500)

If p.OpenWriteDestination(f) Then
If p.SetRGBPicture(pic) Then
If p.SetHeader(False, -1) Then
If p.SetGamma(0) Then
If p.WriteInfo Then
If p.WriteRows Then
If p.WriteEnd Then
MsgBox "OK"
End If
End If
End If
End If
End If
End If
End If

If you pass nil for the file, the data is collected in memory and you can get it on the end using the Finish method.

See also:

Some examples using this method:

PNGWriterMBS.OpenWriteDestination(Path as String) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 19.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Opens the file to write.
Example
Dim file As FolderItem = SpecialFolder.Desktop.Child("test.png")
Dim path As String = file.NativePath

Dim p As New PNGWriterMBS
Dim pic As Picture = LogoMBS(500)

If p.OpenWriteDestination(path) Then
If p.SetRGBPicture(pic) Then
If p.SetHeader(False, -1) Then
If p.SetGamma(0) Then
If p.WriteInfo Then
If p.WriteRows Then
If p.WriteEnd Then
MsgBox "OK"
End If
End If
End If
End If
End If
End If
End If

If you pass "" for the file, the data is collected in memory and you can get it on the end using the Finish method.

See also:

PNGWriterMBS.SetAlphaData(alphas() as Integer, colors() as color) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the alpha data and the color palette.

The array can have up to 256 colors.
The color and the alpha arrays must have the same size.
Returns true on success.

PNGWriterMBS.SetAlphas as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Writes the alpha data to the file.

You must call SetAlphaData before.
Returns true on success.

PNGWriterMBS.SetEXIF(EXIFData as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 19.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Writes the EXIF data block.

Returns true on success or false on failure.

PNGWriterMBS.SetGamma(gamma as Double = 0.0) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Defines the gamma value and other options for the PNG file.

Returns on success.

The gamma parameter defines what gamma correction is applied:
positive value: use the value as the gamma correction
zero: use default value (or value saved in file itself)
negative value: do not correct gamma

Default for Mac is 1.8 and for Windows 2.2.
If you use SRGB, the Gamma must be 2.2.

PNGWriterMBS.SetGrayPicture(pict as picture, mask as picture = nil) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 12.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Copies a picture into the internal buffers for writing a Grayscale image file.

This method sets width, height, type and bpc properties.
Returns true on success.

Mask can be nil.

Some examples using this method:

PNGWriterMBS.SetHeader(Interlace as boolean = false, Filter as Integer = -1, Compression as Integer = -1) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Defines the header options for the PNG file.

Interlace is true the Adam7 interlacing is used.
FilterType specifies the filter:

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
const PNG_FILTER_ALL= 248

Compression can be between 0 (none) to 9 (max). Default is 6. Value -1 means the plugin will not change from default of PNG library. Normally you have no better compression for setting higher than 6, but only burn more CPU power.

PNGWriterMBS.SetICCProfile(name as string, CompressionType as Integer, Profile as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds a ICC Profile to the PNG.

Name is the profile name as an ASCII string.
CompressionType is always 0 (PNG_COMPRESSION_TYPE_BASE).

Some examples using this method:

PNGWriterMBS.SetPalette as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the palette data.

Returns true on success.

PNGWriterMBS.SetPaletteData(colors() as color) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the color palette.

The array can have up to 256 colors.
Returns true on success.

PNGWriterMBS.SetPalettePicture(pict as picture) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Copies a picture into the internal buffers.

You need to define the color palette before calling this method.

This method sets width, height, type and bpc properties.
Returns true on success.

PNGWriterMBS.SetResolution(ResolutionHorizontal as Integer, ResolutionVertical as Integer, Unit as Integer) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 10.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the resolution of the PNG.

Unit is ResolutionUnknown, ResolutionMeter or ResolutionDPI.
Internally the PNG saves only in dots per meter, so the plugin converts DPI to DPM for you.

PNGWriterMBS.SetRGBPicture(pict as picture, mask as picture = nil) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Copies a picture into the internal buffers.
Example
// Write a RGBA PNG file
dim current as Picture = LogoMBS(500)

// create a mask
dim g as Graphics = current.Mask.Graphics
g.ForeColor = &cFFFFFF
g.FillRect 0,0,500,500
g.ForeColor = &c000000
g.FillOval 0,0,500,500

// show in window
window1.Backdrop = current

// and write to file
dim f as FolderItem = SpecialFolder.Desktop.Child("test.png")

dim p as new PNGWriterMBS

if p.OpenWriteDestination(f) then // open file
if p.SetRGBPicture(current, current.mask) 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

This method sets width, height, type and bpc properties.
Returns true on success.

Mask can be nil.

Some examples using this method:

PNGWriterMBS.SetRows(rows() as memoryblock) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 12.5 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Uses the given memoryblocks for row data.

The memory is not copied, so keep the array alive!
This method sets height. You need to set width, bpc, type and rowbytes.
Returns true on success.

Some examples using this method:

PNGWriterMBS.SetsRGB(intent as Integer) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Sets the sRGB intent.

Possible values:

const PNG_sRGB_INTENT_PERCEPTUAL= 0
const PNG_sRGB_INTENT_RELATIVE = 1
const PNG_sRGB_INTENT_SATURATION= 2
const PNG_sRGB_INTENT_ABSOLUTE = 3

Some examples using this method:

PNGWriterMBS.WriteEnd as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Finishes the writing.

Returns true on success.

Do not call if you use WriteRows.

Some examples using this method:

PNGWriterMBS.WriteInfo as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Writes the PNG file header.

Returns true on success.

Do not call if you use WriteRows.

Some examples using this method:

PNGWriterMBS.WriteRow(row as memoryblock)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Writes one row of image data.

The data must be in the RGBA format with one byte per value.
(4 bytes per Pixel)

Returns true on success.

Do not call if you use WriteRows.

Some examples using this method:

PNGWriterMBS.WriteRows as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method PNG MBS Images Plugin 9.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Writes the picture from memory to the file.
Example
// Write a RGB PNG file
dim current as Picture = LogoMBS(500)
dim f as FolderItem = SpecialFolder.Desktop.Child("test.png")

dim p as new PNGWriterMBS

if p.OpenWriteDestination(f) then // open file
if p.SetRGBPicture(current) 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

If you call this method, you need to call SetRGBPicture or SetPalettePicture before and you can't call WriteInfo, WriteRow and WriteEnd.

Some examples using this method:

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


The biggest plugin in space...