ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Test whether a file is an image

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
tcardinal Posted - Mar 15 2017 : 13:29:19
I need to test whether a file is an image or not. Can anyone suggest the best way to do this? I do not need to display the image.

Thanks
5   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Mar 18 2017 : 05:38:46
Actually, a quicker method is to use FindFileFormat.

if FindFileFormat( sFilename, ffContentOnly ) <> ioUnknown then
ShowMessage( 'It's a supported image file!' );

https://www.imageen.com/help/FindFileFormat.html

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
tcardinal Posted - Mar 16 2017 : 05:55:20
Thanks Bill. That's just what I need
w2m Posted - Mar 15 2017 : 14:14:48
You can also just try LoadFromFile then if Aborting is true, the file is not a file format supported by ImageEn or the file is defective. You do not have to view the file.
ImageEnIO.LoadFromFile(iFilename);
if ImageEnIO.Aborting then
begin
  iNotification := NotificationCenter1.CreateNotification;
  try
    iNotification.Name := 'ErrorNotification';
    iNotification.Title := 'Error Opening Image';
    iNotification.AlertBody := 'There was an error opening the image.  The image can not be opened.';
    NotificationCenter1.PresentNotification(iNotification);
  finally
    iNotification.Free;
end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
tcardinal Posted - Mar 15 2017 : 14:01:35
Yes, I should have been more specific - I want to test more than the extension. I was thinking of just trying to open it in a TImageEn, but as I don't need to view I (and so don't need a TControl descendant) wondered if there was a better way. Would using TImageEnIO.LoadFromStream work? I'll give it a go.
w2m Posted - Mar 15 2017 : 13:37:49
Unit iexBitmaps
IsKnownFormat

Declaration
function IsKnownFormat(const FileName : WideString; bIncludeVideoFiles : Boolean = False) : boolean;


Description
Returns true if the specified filename is a supported file format.
By default, this only includes image formats. Set bIncludeVideoFiles to true to include AVI, MPEG and WMV

Note: This method only checks that file extension is recognized (e.g. .JPEG of image.jpeg). To examine the content of the image to determine if it is readable use FindFileFormat

See also: IsKnownSaveFormat

Example
If IsKnownFormat('C:\test.fax') then
  ShowMessage('ok, I can load it');


Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development