Solved

JPEG

Posted on 1998-12-07
6
392 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
6 Comments
 

Expert Comment

by:v_pasupuleti
Comment Utility
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 20 total points
Comment Utility
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
Comment Utility
I understand, but, actually I want to know whether Delphi will raise a exception for a "BUG" JPEG file ?

Andrew
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Expert Comment

by:bryan7
Comment Utility
use      with jpgimage     try jpgxx.loadfromfil...

bryan
0
 
LVL 3

Expert Comment

by:bryan7
Comment Utility
what kind of bugs ?

bryan
0
 

Author Comment

by:andrewyu
Comment Utility
I meant a worong content of JPEG file !

Andrew
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now