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

This usually comes when the Jpeg image is downloaded from Internet and the download is not 100% complete. It can happen even with TImage. Unfortunately Jpeg do not have a checksum to check against.

The only think you can do is whenever this error is thrown to catch it and display more responsive message like "The image is corrupted.".

Since this raises the error:

procedure JpegError(cinfo: j_common_ptr); {$IFDEF LINUX} cdecl; export; {$ENDIF}
begin
  raise EJPEG.CreateFmt(sJPEGError,[cinfo^.err^.msg_code]);

where

sJPEGError = 'JPEG error #%d';

you can try to catch EJPEG error and check for #53 within the message.

Since EJPEG inherits from EInvalidGraphic you can simply catch it with

catch
  on E: EInvalidGraphic do
  begin
    ShowMessage('Image file is corrupted.')
                JFIF/JPEG files can be checked against incompleteness: segment EOI should occur. Also file corruption is not limited to failed downloads.
– AmigoJack
                May 1, 2022 at 0:56

Does it occur to a single jpeg image or with all jpegs you try?

JPEG error #53 error will come due to Insufficient memory.

If file is corrupted, this error may occur.

So opening this image in paint or photoshop and re-saving it in jpeg can solve the problem.

I also had the #53 error. It turned out that the error only occurred after I had erroneously saved a bitmap with the *.jpg extension. The obvious solution was to turn that bitmap into a jpeg and save it then :-).

Please try following to solve 'JPEG error #53' if its occur at this statement TImage.Picture.LoadFromFile('File.jpg')

TImage.Picture.Bitmap.LoadFromFile('File.jpg');

Note that File File.jpg should be exist at provided location.

This is just wrong. How could a TBitmap expect to load a JPEG ? TBitmap can load, uhm, bitmaps. [the downvote is not mine though] – TLama Aug 22, 2013 at 7:23 Can you please mention how you solved your problem by using TAdvPicture, I am also getting similar type of error , but image not corrupted at all I can view image data in SQLite and can extract image properly at another software. Not sure why I am getting JPEG Error #53 – Ninad Avasare Sep 7, 2013 at 6:14 TAdvPicture just won't raise the error, it will display the picture as best it can, and then stop. I have also reverted to this as a solution, since I can't stop the error using a Try... Except, and I dont' really want to have to change the code in the Vcl. TAdvPicture is a component by TMS Software (this is not an advertisement) – KeyszerS Feb 11, 2014 at 11:55 If anyone need a component could be find, If you solved this problem in a correct way with enough explanation and then told about some component I had no problem, but this: you just described an issue as a question and suddenly you find a component and SHAZAM anything just work!!! This is not proper manner here. – QMaster Dec 3, 2015 at 14:35

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.