?
Solved

JPEG

Posted on 1998-12-07
6
Medium Priority
?
401 Views
Last Modified: 2013-11-19
How can I verify a JPEG file is valid or not ? Because it will halt if I pass a file name of invalid JPEG file to LoadFromFile, so, how can I prevent it halt again !

Andrew
0
Comment
Question by:andrewyu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:v_pasupuleti
ID: 1349715
Hi Andrew
Use a try exception in ur code.Put ur Loadfromfile in the try block and a default jpg image in the exception block

Vijay
0
 
LVL 1

Accepted Solution

by:
EmmDieh earned 80 total points
ID: 1349716
A JPEG file contains block markers followed by a block of a certain type. For example a jpeg file will start with the two byte FF D8 and end with the two byte FF D9. Sometimes one ore more extra byte are added to the end of the file due to bugs in transfer software. These files still display but you can delete the extra byte form the end. One time I had a file with more than 1000 extra byte.
I use the following function:
function IsJPEGFileOK(aFileName: string): Boolean;
var
  fs: tFileStream;
  JPEGSign: array[1..2] of Byte;
begin
  Result := false;
  fs := tFileStream.Create(aFileName, fmOpenRead);
  try
    try
        { Check for JPEG-File Beginnmarker }
      fs.Seek(0, soFromBeginning);
      fs.ReadBuffer(JPEGSign, 2);
      Result := (JPEGSign[1] = $FF) and (JPEGSign[2] = $D8);  { $FFD8 }
      if not Result then Exit;
        { Check for JPEG-File Endmarker }
      fs.Seek(-2, soFromEnd);
      fs.ReadBuffer(JPEGSign, 2);
      Result := (JPEGSign[1] = $FF) and (JPEGSign[2] = $D9);  { $FFD9 }
    except
      on E: Exception do
        ErrorMessage('IsJPEGFileOK', E.Message);
    end;
  finally
    fs.Free;
  end;
end;   { IsJPEGFileOK }

0
 

Author Comment

by:andrewyu
ID: 1349717
I understand, but, actually I want to know whether Delphi will raise a exception for a "BUG" JPEG file ?

Andrew
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:bryan7
ID: 1349718
use      with jpgimage     try jpgxx.loadfromfil...

bryan
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1349719
what kind of bugs ?

bryan
0
 

Author Comment

by:andrewyu
ID: 1349720
I meant a worong content of JPEG file !

Andrew
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question