ImageEn, unit iexBitmaps

TIEBitmap.SaveToFile

TIEBitmap.SaveToFile

Declaration

function SaveToFile(const FileName: string; FileType: TIOFileType = ioUnknown): Boolean;

Description

Saves the image to a file (in any format supported by the TImageEnIO class).
FileType specifies the file format to save the image. If ioUnknown is specified, the file extension is used to determine the format (e.g. ioJPEG for "image.jpg").
Returns True on success.

Note:
TIEBitmap only supports saving of a single frame image. To load and save images containing multiple frames, use TIEMultiBitmap
Alternatively, you can use the saving methods of IO
For legacy reasons, SaveToFile() is an alias of Write()

Examples

var
  bmp: TIEBitmap;
begin
  bmp := TIEBitmap.Create();
  bmp.LoadFromFile( 'D:\input.jpg' );
  bmp.SaveToFile( 'D:\output.webp' );
  bmp.Free();
end;

Which is the same as...
with TIEBitmap.Create( 'D:\input.jpg' ) do
begin
  SaveToFile( 'D:\output.webp' );
  Free();
end;

Also the same as...
var
  bmp: TIEBitmap;
  io: TImageEnIO;
begin
  bmp := TIEBitmap.Create();
  io := TImageEnIO.CreateFromBitmap( bmp );
  io.LoadFromFile( 'D:\input.jpg' );
  io.SaveToFile( 'D:\output.webp' );
  io.Free();
  bmp.Free();
end;

// Convert an SVG file to JPEG at max size of 1000x1000 (will be adjusted to maintain aspect ratio)
var
  bmp: TIEBitmap;
begin
  bmp := TIEBitmap.Create();
  try
    bmp.Params.LoadToWidth     := 1000;
    bmp.Params.LoadToHeight    := 1000;
    bmp.Params.AutoScaleImport := True;
    bmp.LoadFromFile( 'D:\Input.svg' );

    bmp.Params.JPEG_Quality    := 90;
    bmp.SaveToFile( 'D:\Output.jpg' );
  finally
    bmp.Free();
  end;
end;

See Also

SaveToStream
LoadFromFile
Filename
IO