Picture.Save

From Xojo Documentation

Method

Picture.Save(file as FolderItem, format as Integer, quality as Integer = QualityDefault)

New in 2010r3

Supported for all project types and targets.

Saves the picture in file specified by file, using the file format specified by format. For the list of available formats, see Picture Class Constants.

Notes

Some valid formats are:

  • Picture.SaveAsDefault
  • Picture.SaveAsDefaultRaster
  • Picture.SaveAsDefaultVector
  • Picture.SaveAsGIF
  • Picture.SaveAsJPEG
  • Picture.SaveAsPNG
  • Picture.SaveAsTIFF
  • Picture.SaveAsWindowsBMP
  • Picture.SaveAsWindowsEMF
  • Picture.SaveAsWindowsWMF
fa-info-circle-32.png
Only JPEG and PNG are supported in console applications

If the FolderItem exists, then it will be overwritten by the new picture file.

If you are using the JPEG format, then there is an optional parameter for the quality of the JPEG. You specify the quality using the following class constants.

Introduced 2010r5
Constant Value
QualityDefault -1
QualityMax 100
QualityHigh 80
QualityMedium 50
QualityLow 25
QualityMin 0

Example

The following example saves the contents of an ImageWell to a temporary file on disk and then reads it into a BinaryStream for storage in a database. The property f as FolderItem is a property of the window.

Dim imageData As String
Dim bs As BinaryStream
Dim f As FolderItem
If ImageWell1.Image <> Nil Then
// Get a temporary file to save the image to
If Picture.IsExportFormatSupported(Picture.FormatJPEG) Then
f = SpecialFolder.Temporary.Child("TempImage.jpg")

// Save the image out to the file
ImageWell1.Image.Save(f, Picture.SaveAsJPEG)
End If

// Open the file as a BinaryStream and read the data in
bs = BinaryStream.Open(f, False)
If bs <> Nil Then
imageData = bs.Read(bs.Length)
bs.Close
End If

// delete the temporary file if it exists
If f.Exists Then
f.Delete
End If
End If