无法从byte []读取JPEG文件 [英] Failure to read JPEG file from byte[]

查看:232
本文介绍了无法从byte []读取JPEG文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人遇到过在java中加载JPEG文件的问题?我们的一个客户端正在发送无法解析的文件,但这些文件可以在Windows中打开。 (我们收到的其他99%的jpeg文件,处理没有任何问题)

Has anyone ever had an issue with Loading JPEG files in java? One of our clients is sending files that cannot be resolved, but these same files can be opened in windows. (the other 99% of jpeg files we recieve, process without any problems)

我已经尝试了几个库来阅读这些:

I have tried a couple of libraries to read these:

itextpdf : com.itextpdf.text.Jpeg (getInstance(imageData) - gives  "java.io.IOException: Premature EOF while reading JPG."
sanselan : org.apache.sanselan.ImageInfo ( Sanselan.getImageInfo(imageData) gives "java.io.IOException: Invalid Segment: insufficient data")
where imageData is a byte[]

这里的错误告诉我jpegs坏了,但是,这并不能解释为什么它们仍然可见。

The errors here suggest to me that the jpegs are broken, however, this does not explain why they are still viewable.

如果有人有任何建议,我将非常感激

If anyone has any suggestions, I would be most grateful

谢谢

推荐答案

我所用的解决方案是运行我们通过当前进程识别类型的字节数组。如果这不能识别类型,那么我取字节数组并强制将其保存为JPEG。这可以是r e读取并推回当前流程。

The "solution" I have gone for is to run the byte array we recieve through our current process which identifies type. If this can't identify the type, then I take the byte array and forcably save it to a JPEG. This can then be re read and pushed back through the current process.

有点hacky,但这只是一个工作几个月。

Bit hacky, but its just a work around for a couple of months.

感谢大家的帮助!

这篇关于无法从byte []读取JPEG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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