在TopenDialog设置好filter
比如设置为:
Alle Dateien (*.bw;*.cel;*.icb;*.pcc;*.pcd;*.pcx;*.pic;*.rgb;*.scr;*.tga;*.vda;*.vst;*.win;*.gif;*.tga;*.pcd;*.pcx;*.png;*.jpg;*.jpeg;*.bmp;*.ico;*.emf;*.wmf)|*.bw;*.cel;*.icb;*.pcc;*.pcd;*.pcx;*.pic;*.rgb;*.scr;*.tga;*.vda;*.vst;*.win;*.gif;*.tga;*.pcd;*.pcx;*.png;*.jpg;*.jpeg;*.bmp;*.ico;*.emf;*.wmf|SGI black/white images (*.bw)|*.bw|Autodesk images (*.cel)|*.cel|Truevision images (*.icb)|*.icb|ZSoft PCC images (*.pcc)|*.pcc|Kodak Photo-CD images (*.pcd)|*.pcd|ZSoft PCX images (*.pcx)|*.pcx|Autodesk images (*.pic)|*.pic|SGI true color images (*.rgb)|*.rgb|Word 5.x screen capture images (*.scr)|*.scr|Truevision images (*.tga)|*.tga|Truevision images (*.vda)|*.vda|Truevision images (*.vst)|*.vst|Truevision images (*.win)|*.win|GIF Image (*.gif)|*.gif|TGA-Format (*.tga)|*.tga|PCD-Format (*.pcd)|*.pcd|PCX-Format (*.pcx)|*.pcx|PNG-Format (*.png)|*.png|JPEG Bilddatei (*.jpg)|*.jpg|JPEG Bilddatei (*.jpeg)|*.jpeg|Bitmaps (*.bmp)|*.bmp|Symbole (*.ico)|*.ico|Erweiterte Metadateien (*.emf)|*.emf|Metadateien (*.wmf)|*.wmf22
再参照以下代码:
procedure TfrmColor.Button13Click(Sender: TObject);
Var
jpeg: TJPEGImage;
bmp: TBitmap;
FileExt: string[4];
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
FileExt := AnsiUpperCase(ExtractFileExt(OpenDialog1.Filename));
if (FileExt = '.BMP') or (FileExt = '.ICO') or (FileExt = '.WMF') or
(FileExt = '.EMF') or (FileExt = '.JPG') then
begin
Image1.Picture.LoadFromFile(OpenDialog1.Filename);
if (FileExt = '.BMP') then
begin
Caption := Caption +
Format(' (%d x %d)', [Image1.Picture.Width, Image1.Picture.Height]);
Image1.Picture := Image1.Picture;
end
else
if (FileExt = '.JPG') then
begin
Caption := Caption +
Format(' (%d x %d)', [Image1.Picture.Width, Image1.Picture.Height]);
Image1.Picture := Image1.Picture;
jpeg:= TJPEGImage.Create;
try
jpeg.LoadFromFile(OpenDialog1.Filename);
try
image1.Picture.bitmap.Assign( jpeg );
// image1.Picture.bmp.SaveTofile( ChangeFileExt( filename, '.BMP' ));
finally
end;
finally
jpeg.free
end;
end
else
if FileExt = '.ICO' then
begin
Icon := Image1.Picture.Icon;
Image1.Picture.Icon := Icon;
end;
if (FileExt = '.WMF') or (FileExt = '.EMF') then
Image1.Picture.Metafile := Image1.Picture.Metafile;
end;
end;
end;