Autor Beitrag
schlumsch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

alles Win :)
Delphi 2005 Prof, Delphi 2007
BeitragVerfasst: Di 15.12.09 22:02 
Hallo,

ich möchte die Files aus einem Dir prüfen ob es sich um ein Bild handelt und dann damit "etwas" machen. Nun kann ich mir mit extractfileext die Endung holen und daraufhin entscheiden ... soweit klar... aber da gibt es doch sicher auch eine andere Lösung oder?

Meine Idee ist die folgende:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Function isPicture(filename:String):boolean;
begin
 try
 formdirectoryselect.image1.Picture.LoadFromFile(filename);
 result := true;
 except
 result := false;
 end;
end;


Alledings habe ich da das Problem, dass mein Programm leider dennoch unterbrochen wird und "abstürzt". Habe ich da was beim Exceptionhandling falsch gemacht?

Moderiert von user profile iconNarses: Überflüssige Zeilenumbrüche/Leerzeilen entfernt.

_________________
icq 102779206
"God is real, unless declared integer..."
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 15.12.09 23:14 
Starte das Programm mal ohne Delphi..

_________________
PROGRAMMER: A device for converting coffee into software.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 15.12.09 23:30 
Moin!

user profile iconschlumsch hat folgendes geschrieben Zum zitierten Posting springen:
aber da gibt es doch sicher auch eine andere Lösung oder?

Meine Idee ist die folgende:
Du willst nicht wirklich die Datei laden, um zu prüfen, ob das ein Bild ist, oder?! :shock: Das dürfte der Performance-Killer schlechthin sein. :!:

Sicher ist die Methode die Dateierweiterung zu analysieren nicht 100%ig, aber auf jeden Fall um krasse Längen schneller! :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
schlumsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

alles Win :)
Delphi 2005 Prof, Delphi 2007
BeitragVerfasst: Mi 16.12.09 00:07 
Hmm echt? Und ich war schon stolz auf meine Idee mit dem Image *g* :)

_________________
icq 102779206
"God is real, unless declared integer..."
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 16.12.09 02:41 
Haben nicht so ziemlich alle Grafikformate einen Header den man auslesen könnte? Der wäre dann ja denk ich nicht so groß und man könnte ihn ja auch bequem auslesen.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 16.12.09 02:56 
user profile iconschlumsch hat folgendes geschrieben Zum zitierten Posting springen:
Hmm echt? Und ich war schon stolz auf meine Idee mit dem Image *g* :)
Nur dass da auch nur an Hand der Dateierweiterung geprüft wird um welches Format es sich handelt. Und wenn diese zu keinem passt oder das Bild nicht entsprechend der Erweiterung geladen werden konnte, gibt es eine Exception.

Insofern kannst du auf diese Weise niemals ein Bild in einer falschen Erweiterung erkennen. Du kannst so maximal feststellen, wenn eine Datei mit einer bekannten Bild-Dateierweiterung nicht entsprechend geladen wird...

Und da Delphi nur sehr wenige Formate kennt, wirst du also nur sehr wenige der Bildformate so erkennen können. Von den genannten Performanceproblemen einmal ganz abgesehen, das wurde ja schon gesagt.
schlumsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

alles Win :)
Delphi 2005 Prof, Delphi 2007
BeitragVerfasst: Mi 16.12.09 11:03 
Hmkay dann entscheide ich einfach aufgrund der Dateiendung... gibt zwar ne größere if-scghleife aber was solls. Dank euch jedenfalls, lg

_________________
icq 102779206
"God is real, unless declared integer..."
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mi 16.12.09 11:10 
user profile iconschlumsch hat folgendes geschrieben Zum zitierten Posting springen:
Hmkay dann entscheide ich einfach aufgrund der Dateiendung... gibt zwar ne größere if-scghleife aber was solls. Dank euch jedenfalls, lg


Es gibt keine If-Schleifen!!!!111einseinself
Das sind If-Anweisungen.

Beste Grüße
schlumsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

alles Win :)
Delphi 2005 Prof, Delphi 2007
BeitragVerfasst: Mi 16.12.09 11:34 
schön das du dich darüber aufregen kannst

_________________
icq 102779206
"God is real, unless declared integer..."
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mi 16.12.09 11:47 
find ich auch. und wenn du als Programmierer/Informatiker ernst genommen werden willst, solltest du solche Details beachten. Man kommt bei Kollegen sonst nicht soooo seriös rüber wie man vielleicht hofft/will.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
schlumsch Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122

alles Win :)
Delphi 2005 Prof, Delphi 2007
BeitragVerfasst: Mi 16.12.09 12:13 
Ja passt schon... in der eifer des Gefechtes hab ich das so fix hingekliert, mir ist schon klar das es sich bei if um keine schleife handelt

_________________
icq 102779206
"God is real, unless declared integer..."