RAD Studio VCL Reference
|
Returns a file filter compatible with the Filter property of an Open or Save dialog.
function GraphicFilter(GraphicClass: TGraphicClass): string;
AnsiString GraphicFilter(TGraphicClass GraphicClass);
Call GraphicFilter to obtain a value for the Filter property of an Open, Open Picture, Save Picture or Save dialog box. The GraphicClass parameter can specify one of these values: TBitmap, TGraphic, TIcon, TMetafile, or a user-defined descendant of TGraphic.
These are the strings that are returned for each built-in graphics class when the AllFilter parameter is true. (When AllFilter is false, the section labelled "All" is omitted):
Graphic class |
Filter string returned |
Bitmaps (*.bmp;*.png;*.xpm)|*.bmp;*.png;*.xpm | |
Icons (*.ico)|*.ico | |
All (*.bmp;*.png;*.xpm*.ico)|*.bmp;*.png;*.xpm*.ico|Bitmaps (*.bmp;*.png;*.xpm)|*.bmp;*.png;*.xpm|Icons (*.ico)|*.ico | |
Bitmaps (*.bmp)|*.bmp | |
Icons (*.ico)|*.ico | |
All (*.emf;*.wmf)|*.emf;*.wmf|Enhanced Metafiles (*.emf)|*.emf|Metafiles(*.wmf)|*.wmf | |
All (*.bmp;*.ico;*.emf;*.wmf)|*.bmp;*.ico;*.emf; *.wmf|Bitmaps (*.bmp)|*.bmp|Icons (*.ico)|*.ico|Enhanced Metafiles (*.emf)|*.emf|Metafiles(*.wmf)|*.wmf |
Graphic class |
Filter string returned |
Bitmaps (*.bmp)|*.bmp | |
Icons (*.ico)|*.ico | |
All (*.emf;*.wmf)|*.emf;*.wmf|Enhanced Metafiles (*.emf)|*.emf|Metafiles(*.wmf)|*.wmf | |
All (*.bmp;*.ico;*.emf;*.wmf)|*.bmp;*.ico;*.emf; *.wmf|Bitmaps (*.bmp)|*.bmp|Icons (*.ico)|*.ico|Enhanced Metafiles (*.emf)|*.emf|Metafiles(*.wmf)|*.wmf |
C++ Examples:
/* This code displays a Save Picture dialog box with the TBitmap default extension that is added automatically to files that are given no extension. Confirm that the bitmap file has been saved under the filename and path specified. */ #include <memory> //for STL auto_ptr class void __fastcall TForm1::Button1Click(TObject *Sender) { AnsiString NewFileName, OldFileName; SavePictureDialog1->DefaultExt = GraphicExtension(__classid(Graphics::TBitmap)); SavePictureDialog1->Filter = GraphicFilter(__classid(Graphics::TBitmap)); OldFileName = "factory.bmp"; if (SavePictureDialog1->Execute()) { NewFileName = SavePictureDialog1->FileName; std::auto_ptr<TFileStream> OldFile(new TFileStream(OldFileName, (fmOpenRead | fmShareDenyWrite))); std::auto_ptr<TFileStream> NewFile(new TFileStream(NewFileName, (fmCreate | fmShareDenyRead))); NewFile->CopyFrom(OldFile.get(), OldFile->Size); }; } void __fastcall TForm1::FormCreate(TObject *Sender) { Image1->Picture->LoadFromFile("../factory.bmp"); }
Delphi Examples:
{ This code displays a Save Picture dialog box with the TBitmap default extension that is added automatically to files that are given no extension. Confirm that the bitmap file has been saved under the filename and path specified. } procedure TForm1.Button1Click(Sender: TObject); var NewFileName, OldFileName: string; NewFile, OldFile: TFileStream; begin SavePictureDialog1.DefaultExt := GraphicExtension(TBitmap); SavePictureDialog1.Filter := GraphicFilter(TBitmap); OldFileName := 'factory.bmp'; if SavePictureDialog1.Execute then begin NewFileName := SavePictureDialog1.FileName; OldFile := TFileStream.Create( OldFileName, fmOpenRead or fmShareDenyWrite); try NewFile := TFileStream.Create( NewFileName, fmCreate or fmShareDenyRead); try NewFile.CopyFrom(OldFile, OldFile.Size); finally FreeAndNil(NewFile); end; finally FreeAndNil(OldFile); end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin Image1.Picture.LoadFromFile('factory.bmp'); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|