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

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

问题描述

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

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天全站免登陆