RAD Studio VCL Reference
[Link] Method
TPicture Class | TPicture Members | Graphics Namespace | Description | See Also
Collapse All
Writes the picture to disk.
Pascal
procedure SaveToFile(const Filename: string);
C++
__fastcall SaveToFile(const AnsiString Filename);
Description
Use SaveToFile to save a TPicture object to the file specified in Filename.
The saved picture can be loaded to another TPicture or to an appropriate TGraphic descendant by calling its LoadFromFile method.
C++ Examples:
Copy Code
/*
This example converts a specified icon to a bitmap. To run
this example, add an image, a button, and an Open dialog to
a form. Name the button ConvertIcon2Bitmap, and add the
following code as its OnClick event handler.
*/
#include <memory> //for STL auto_ptr class
void __fastcall TForm1::ConvertIcon2BitmapClick(TObject *Sender)
{
OpenDialog1->DefaultExt = ".ICO";
OpenDialog1->Filter = "icons (*.ico)|*.ICO";
OpenDialog1->Options << ofOverwritePrompt << ofFileMustExist << ofHideReadOnly;
if (OpenDialog1->Execute())
{
std::auto_ptr<TIcon> pi(new Graphics::TIcon);
AnsiString as;
pi->LoadFromFile(OpenDialog1->FileName);
as = ChangeFileExt(OpenDialog1->FileName,".BMP");
Image1->Width = pi->Width;
Image1->Height = pi->Height;
Image1->Canvas->Draw(0, 0, [Link]());
Image1->Picture->SaveToFile(as);
ShowMessage(OpenDialog1->FileName + " Saved to " + as);
}
}
Delphi Examples:
Copy Code
{
This example converts a specified icon to a bitmap. To run
this example, add an image, a button, and an Open dialog to
a form. Name the button ConvertIcon2Bitmap, and add the
following code as its OnClick event handler.
}
procedure TForm1.ConvertIcon2BitmapClick(Sender: TObject);
var
s : string;
Icon: TIcon;
begin
[Link] := '.ICO';
[Link] := 'icons (*.ico)|*.ICO';
[Link] := [ofOverwritePrompt, ofFileMustExist, ofHideReadOnly ];
if [Link] then
begin
Icon := [Link];
try
[Link]([Link]);
s:= ChangeFileExt([Link],'.BMP');
[Link] := [Link];
[Link] := [Link];
[Link](0,0,Icon);
[Link](s);
ShowMessage([Link] + ' Saved to ' + s);
finally
[Link];
end;
end;
end;
See Also
LoadFromFile
LoadFromFile
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!