Home > Language Reference > Classes > Bitmap

SaveToPNG Method

Saves the bitmap to a PNG file.

Syntax

Public Sub SaveToPNG(ByRef objStream As Stream)

ParameterDescription
objStreamStream where data are to be written.

Remarks

The SaveToPNG method writes the bitmap into the specified stream in the PNG format. If the object does not contain an image and is associated with a resource, it is loaded. Otherwise, a runtime error occurs.

The objStream parameter is the stream where data are to be written. It can be any properly initialized stream object. After the operation completes, the stream pointer is always set to the first byte after the image. The following example saves a bitmap to a file:

Public Sub Export(ByRef bm As Bitmap, ByRef sFilename As String, ByVal iVolRef As Integer)
  Dim f As New StreamFile
  
  f.Open iVolRef, sFilename, hbModeCreateAlways+hbModeReadWrite
  bm.SaveToPNG f
  f.Close
End Sub

The HB++ runtime library only supports generating true color PNG files. Therefore, the bitmap may require to be converted to a 16-bit bitmap before the export can take place. This can result in a runtime error if memory is low.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A