如何判断照片是否损坏? [英] How to determine if a photo is corrupted?

查看:60
本文介绍了如何判断照片是否损坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我必须确定照片是否已损坏,并相应地将其标记为损坏.

I have a requirement where in I have to determine whether a photo is corrupted and accordingly tag it as such.

另一件事,我需要确定一个图像是否有错误的扩展名.我所说的错误扩展名的意思是,有时我会遇到一张带有 jpg 扩展名的照片,但是当我将这张照片加载到 IrfanView 时,它会报告该照片与扩展名的格式不同.

Another thing, I need is to determine if an Image has got wrong extension. What I mean by wrong extension is that sometimes I have come across a photo that has extension of jpg but when I load this photo into IrfanView it reports that the photo is in different format that the extension.

我如何在 Delphi 中执行此操作.

How can I do this in Delphi.

推荐答案

我有一个要求,我必须确定照片是否已损坏,并相应地将其标记为损坏.

I have a requirement where in I have to determine whether a photo is corrupted and accordingly tag it as such.

您可以尝试一些事情,但对于某些文件格式(例如:BMP、JPEG 在某种程度上),只有人类才能最终决定文件是否正常或已损坏.最简单的测试是简单地将文件加载到相应的对象(TJpegImage、TPngObject 等)中.如果您在加载时遇到异常,您肯定已经损坏了文件.不幸的是,如果没有引发异常,您就不能真正说文件没有损坏.我已经看到损坏的 JPEG 文件可以很好地加载到 Delphi TImage 并且可以用 Windows 的图像查看器打开,但对于人类观察者来说显然已损坏.对于 BMP 图像,它甚至更清晰:打开位图,覆盖文件中间的一些字节,然后在查看器中打开它.任何自动化系统如何判断位图中间那些颜色错误的位实际上是错误的?

You can try some things, but with certain file formats (example: BMP, JPEG to some extent) only a human can ultimately decide if the file is OK or corrupted. The simplest test is to simply load the file into a corresponding object (TJpegImage, TPngObject, etc). If you get an exception while loading you've surely got a corrupted file. Unfortunately if no exception is raised you can't really say the file is not corrupted. I've seen corrupted JPEG files that load just fine into a Delphi TImage and can be opened with Windows's Image Viewer, but are obviously corrupted to a human observer. With BMP images it's even clearer: open up a bitmap, overwrite some bytes in the middle of the file and then open it in a viewer. How can any automated system tell those wrongly colored bits in the middle of the bitmap are actually wrong?

另一件事,我需要确定一个图像是否有错误的扩展名.我所说的错误扩展名的意思是,有时我会遇到一张带有 jpg 扩展名的照片,但是当我将这张照片加载到 IrfanView 时,它会报告该照片与扩展名的格式不同.

Another thing, I need is to determine if an Image has got wrong extension. What I mean by wrong extension is that sometimes I have come across a photo that has extension of jpg but when I load this photo into IrfanView it reports that the photo is in different format that the extension.

如何做一些相同的事情,尝试将文件加载到与其扩展名对应的对象中,如果失败,尝试打开其他格式?这应该很容易.

How about doing some of the same, trying to load the file into the object that corresponds to it's extension, and if you fail, try opening up with some other formats? This should be easy.

或者,您可以研究图像标头:大多数文件格式以短签名开头,几个字节.您可以查找所有图像文件格式的文档并找到签名,或者您可以简单地打开大量文件并在前 4 个字节中查找模式.我会选择第二种选择,因为为所有图像文件格式找到合适的文档可能是一个挑战.

Alternatively you can investigate image headers: Most file formats start with a short signature, a few bytes. You can look up the documentation of all image file formats and find the signature, or you can simply open up an large number of files and look for a pattern in the first 4 bytes. I'd go for this second alternative since finding proper documentation for all image file formats might be a challenge.

这篇关于如何判断照片是否损坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆