Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Why sometimes in the Open dialog I cannot load the same file extension on the Open dialog filters, so I had to refresh the first to find the file.
E.g.:
Filter = *.jpg
I can not find the file
*.jpg
in Explorer Open dialog, but there are a lot of images with extension
*.jpg
.
This happens on Win 7 OS [x86 & x64]. The compiler version I am using is Delphi 7.
procedure TForm1.Button1Click(Sender: TObject);
JpgIF: TJpegImage;
BmpIF: TBitmap;
begin
JpgIF := TJpegImage.Create;
BmpIF := TBitmap.Create;
OD.FileName := '';
OD.DefaultExt := '*.jpg;*.jpeg;*.psd;*.tga*.png;*.gif;*.bmp';
OD.Filter := 'JPG|*.jpg|Jpeg|*.jpeg|PSD|*.psd|TGA|*.tga|PNG|*.png|GIF|*.gif|Bmp|*.bmp';
if not OD.Execute then
else if LowerCase(ExtractFileExt(OD.FileName)) = '.jpg' then
begin
JpgIF.LoadFromFile(OD.FileName);
Img1.Picture.Bitmap.Assign(JpgIF);
begin
if LowerCase(ExtractFileExt(OD.FileName)) = '.bmp' then
begin
BmpIF.LoadFromFile(OD.FileName);
Img1.Picture.Bitmap.Assign(BmpIF);
//etc...
JpgIF.Free;
BmpIF.Free;
–
–
–
You need to add Jpeg, GIFImg, PngImage to uses that allows reading and writing these file types.
I have forgotten if GIFImg and PngImage is distributed with Delphi 7 so if these units are not available you need to obtain other units that provide support for the file types you want to open such as GraphicsEx.
The OpenDialog.DefaultExt contains the default extension to add to the filename if the user omits the extension when a file is saved. Only use one extension for the defaultext property. Only add file types to the filter that have a corresponding unit in uses unless there is a third-party unit that provides additional TGraphic filetype support in uses (GraphicEx or ImageEn for example).
Uses Jpeg, GIFImg, PngImage;
OD.DefaultExt := 'jpg';
// or
OD.DefaultExt := GraphicExtension(TJpegImage);
OD.Filter := 'JPG|*.jpg|Jpeg|*.jpeg|PNG|*.png|GIF|*.gif|Bmp|*.bmp';
If a third-party unit is used such as GraphicsEx, then you can add the units supported file types to the filter. You can download GraphicEx here: http://www.soft-gems.net/index.php/all-downloads.
Uses GraphicEx;
If you use ImageEn then add ImageEnIO to uses and then register the file formats provided by ImageEnIO in OnFormCreate and unregister the file formats in OnFormDestroy:
Uses ImageEnIO;
procedure TForm1.FormCreate(Sender: TObject);
begin
{ Register ImageEnIO file types to TGraphic }
ImageEnIO.IERegisterFormats;
OD.Filter := GraphicFilter(TGraphic);
procedure TForm1.FormDestroy(Sender: TObject);
begin
{ UnRegister ImageENIO file types }
IEUnRegisterFormats;
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.