问题描述
我需要能够验证如果JPEG图像是有效的,没有损坏。这是不一样的问题210650 它只是要求要验证它是,实际上,JPEG图像。从图像加载时进行验证,例如:
I need to be able to validate if a JPEG image is valid and not corrupted. This is not the same as question 210650 which just asks wants to validate that it is, in fact, a JPEG image. Loading from Image with validation eg:
var testJpg =
Bitmap.FromStream(filename, useEmbeddedColorManagement, validateData);
将不会抛出异常的截取图像。目前,我们的解决方法是尝试打开该文件的外部GD脚本,并解析从gdImageCreateFromJpeg抛出的任何错误。
will not throw an exception for clipped images. Currently our solution is to try to open the file an external GD script and parse for any errors thrown from gdImageCreateFromJpeg.
gdImagePtr im;
im = gdImageCreateFromJpeg(testFile);
fclose(in);
但必须有一个验证,一个JPEG,不仅有效一些净code的地方,但包含了完整的图像?
But there has to be some .Net code somewhere that validates that a JPEG is not only valid, but contains the complete image?
推荐答案
以 JPEG从维基百科参考结构,也许你可以看看从流EOI字节?
Taking JPEG reference structure from Wikipedia, maybe you can look for EOI byte from the stream?
这篇关于如何验证JPEG图像在C#/。NET是没有损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!