Description
The Picture.SaveToFile
method saves the image represented by the Picture
object to a file. The image format is specified by the method parameters.
Declaration
PictureObj.SaveToFile(FileName, Configuration)
PictureObj | An expression, variable or parameter that specifies a reference to a Picture object | |||
FileName | [in] | Required | String | |
Configuration | [in] | Optional | An ImageConfiguration object |
|
Result | Boolean |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
FileName
The name of the file to which you want to save the image.
If you omit the Configuration parameter, the file extension specifies the format of the saved image:
Format | Extension |
---|---|
BMP | .bmp or .dib |
JPEG | .jpg, .jpeg, .jpe or .jfif |
PNG | .png |
TIFF | .tif or .tiff |
GIF | .gif |
ICO | .ico |
If the FileName parameter specifies a file that does not exist, the method will create the file. If the parameter specifies a file that already exists, the method will replace the file.
If the parameter specifies a file residing in a non-existent location, the method will fail to save the file. To avoid possible problems, you can first create the needed location by using the aqFileSyste.CreateFolder
method.
Configuration
An ImageConfiguration
object that specifies the format, color and compression settings for the image to be saved. To create a new ImageConfiguration
object, use the Picture.CreatePictureConfiguration
method.
If this parameter is omitted, the image format is specified by the file extension (see description of the FileName parameter).
Result Value
True, if the image is successfully saved to the specified file, and False otherwise.
Example
The following example demonstrates how to create an empty Picture
object using the Utils.Picture
method and how to work with images using methods of the Picture
object.
JavaScript
function Test1()
{
var Pict, NewPict, x, y;
// Creates a new empty Picture object
Pict = Utils.Picture;
// Loads the image from a file and posts it to the log
Pict.LoadFromFile("D:\\Data\\my_image.png");
Log.Picture(Pict);
// Obtains the bounds of the new image
x = Pict.Size.Width - 10;
y = Pict.Size.Height - 10;
// Obtains the new Picture object containing the specified rectangular area of the loaded image
NewPict = Pict.GetRect(0, 0, x, y);
// Changes the color of the top left pixel of the new image to the red color
NewPict.$set("Pixels", 0, 0, clRed);
// Saves the obtained picture to the new file and posts the image to the log
NewPict.SaveToFile("D:\\Data\\my_new_image.png");
Log.Picture(NewPict);
}
JScript
function Test1()
{
var Pict, NewPict, x, y;
// Creates a new empty Picture object
Pict = Utils.Picture;
// Loads the image from a file and posts it to the log
Pict.LoadFromFile("D:\\Data\\my_image.png");
Log.Picture(Pict);
// Obtains the bounds of the new image
x = Pict.Size.Width - 10;
y = Pict.Size.Height - 10;
// Obtains the new Picture object containing the specified rectangular area of the loaded image
NewPict = Pict.GetRect(0, 0, x, y);
// Changes the color of the top left pixel of the new image to the red color
NewPict.Pixels(0,0)= clRed;
// Saves the obtained picture to the new file and posts the image to the log
NewPict.SaveToFile("D:\\Data\\my_new_image.png");
Log.Picture(NewPict);
}
Python
def Test1():
# Creates a new empty Picture object
Pict = Utils.Picture;
# Loads the image from a file and posts it to the log
Pict.LoadFromFile("D:\\Data\\my_image.png")
Log.Picture(Pict)
# Obtains the bounds of the new image
x = Pict.Size.Width - 10
y = Pict.Size.Height - 10
# Obtains the new Picture object containing the specified rectangular area of the loaded image
NewPict = Pict.GetRect(0, 0, x, y)
# Changes the color of the top left pixel of the new image to the red color
NewPict.Pixels[0,0] = clRed
# Saves the obtained picture to the new file and posts the image to the log
NewPict.SaveToFile("D:\\Data\\my_new_image.png")
Log.Picture(NewPict)
VBScript
Sub Test1
Dim Pict, NewPict, x, y
' Creates a new empty Picture object
Set Pict = Utils.Picture
' Loads the image from a file and posts it to the log
Call Pict.LoadFromFile("D:\Data\my_image.png")
Log.Picture(Pict)
' Obtains the bounds of the new image
x = Pict.Size.Width - 10
y = Pict.Size.Height - 10
' Obtains the new Picture object containing the specified rectangular area of the loaded image
Set NewPict = Pict.GetRect(0, 0, x, y)
' Changes the color of the top left pixel of the new image to the red color
NewPict.Pixels(0,0)= clRed
' Saves the obtained picture to the new file and posts the image to the log
Call NewPict.SaveToFile("D:\Data\my_new_image.png")
Log.Picture(NewPict)
End Sub
DelphiScript
procedure Test1;
var Pict, NewPict, x, y;
begin
// Creates a new empty Picture object
Pict := Utils.Picture;
// Loads the image from a file and posts it to the log
Pict.LoadFromFile('D:\Data\my_image.png');
Log.Picture(Pict);
// Obtains the bounds of the new image
x := Pict.Size.Width - 10;
y := Pict.Size.Height - 10;
// Obtains the new Picture object containing the specified rectangular area of the loaded image
NewPict := Pict.GetRect(0, 0, x, y);
// Changes the color of the top left pixel of the new image to the red color
NewPict.Pixels(0,0) := clRed;
// Saves the obtained picture to the new file and posts the image to the log
NewPict.SaveToFile('D:\Data\my_new_image.png');
Log.Picture(NewPict);
end;
C++Script, C#Script
function Test1()
{
var Pict, NewPict, x, y;
// Creates a new empty Picture object
Pict = Utils["Picture"];
// Loads the image from a file and posts it to the log
Pict["LoadFromFile"]("D:\\Data\\my_image.png");
Log["Picture"](Pict);
// Obtains the bounds of the new image
x = Pict["Size"]["Width"] - 10;
y = Pict["Size"]["Height"] - 10;
// Obtains the new Picture object containing the specified rectangular area of the loaded image
NewPict = Pict["GetRect"](0, 0, x, y);
// Changes the color of the top left pixel of the new image to the red color
NewPict["Pixels"](0,0)= clRed;
// Saves the obtained picture to the new file and posts the image to the log
NewPict["SaveToFile"]("D:\\Data\\my_new_image.png");
Log["Picture"](NewPict);
}
See Also
SaveToClipboard Method
LoadFromFile Method
CreatePictureConfiguration Method
Options Object