WritePNGFile Method

NI Vision for Visual Basic

WritePNGFile Method

Syntax

CWIMAQVision.WritePNGFile SourceImage, Path [, PNGFileOptions = 750] [, ColorPalette]

Return Type

Long

On success, this method returns 0. On failure, this method returns a negative number.

Purpose

Writes an image to a file in PNG format.

Remarks

Use this method with U8, U16, I16, RGB32, and RGBU64 images.

PNG format always stores images in a lossless manner.

Parameters

SourceImage As CWIMAQImage

The image to write to a file.

Path As String

The name of the file.

PNGFileOptions As Variant

[Optional] Options to use when writing the file. You can set this parameter to one of two different types of values. Set this parameter to a compression speed value if you want to write a PNG file at a compression other than the default. If you want to specify further options, set this parameter to a CWIMAQPNGFileOptions object.

This parameter has a default value of 750.

ColorPalette As Variant

[Optional] A color table to associate with U8 images. The default is a grayscale palette. If the color table has less than 256 elements, the function fills the remaining elements with grayscale values to increase the size of the color table to 256 elements.

Example

Dim Filename1 As String
Dim Filename2 As String
Dim Filename3 As String
Dim PngOptions As New CWIMAQPNGFileOptions

'Write an image in Viewer1 to an PNG file with default compression
'The name of the file is in Filename1
CWIMAQVision1.WritePNGFile CWIMAQViewer1.Image, Filename1

'Write an image in Viewer1 to a PNG file at greater compression (lower compression speed)
'than the default. The name of the file is in Filename2
CWIMAQVision1.WritePNGFile CWIMAQViewer1.Image, Filename2, 300

'Write an image in Viewer1 to a PNG file at greater compression (lower compression speed)
'than the default and with a the color palette that is stored in Viewer1
'The name of the file is in Filename3
PngOptions.CompressionSpeed = 300
CWIMAQVision1.WritePNGFile CWIMAQViewer1.Image, Filename4, PngOptions, CWIMAQViewer1.Palette

See Also

CWIMAQPNGFileOptions

CWIMAQTIFFFileOptions

ReadImage

WriteImageAndVisionInfo

WriteBMPFile

WriteJPEGFile

WriteJPEG2000File

WriteTIFFFile