如何解决如何从Java中的Thumbs.db中提取图像?
| 喜 我阅读了有关POI项目的内容,并尝试从thumbs.db中提取图像,但是在代码中出现异常..代码osInputStream stream = new FileInputStream(\"C:\\\\Thumbs.db\");
POIFSFileSystem fs = new POIFSFileSystem(stream);
DirectoryEntry root = fs.getRoot();
Entry entry = root.getEntry(\"2\");
DocumentInputStream is = fs.createDocumentInputStream(entry.getName());
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is);
JPEGDecodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(4,JPEGDecodeParam.COLOR_ID_RGBA);
decoder.setJPEGDecodeParam(param);
BufferedImage originalBufferedImage = decoder.decodeAsBufferedImage();
以\“ com.sun.image.codec.jpeg.ImageFormatException获取异常:不是JPEG文件:从0x0c 0x00 \开始”
以上情况有什么问题?
您能建议其他方法来完成上述任务吗?
解决方法
您需要先读取Thumbs.db文件的标题,然后才能开始提取图像。尝试使用我在下面添加的更改,它应该删除您得到的ѭ1。
InputStream stream = new FileInputStream(\"C:\\\\Thumbs.db\");
POIFSFileSystem fs = new POIFSFileSystem(stream);
DirectoryEntry root = fs.getRoot();
Entry entry = root.getEntry(\"2\");
DocumentInputStream is = fs.createDocumentInputStream(entry.getName());
//Added to read the header lines and fix the ImageFormatException
int header_len = is.read();
for (int i = 1; i < header_len; i++) {
is.read();
}
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is);
JPEGDecodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(4,JPEGDecodeParam.COLOR_ID_RGBA);
decoder.setJPEGDecodeParam(param);
BufferedImage originalBufferedImage = decoder.decodeAsBufferedImage();
希望对您有所帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。