将字节数组转换为Java中的映像 - 不知道类型 [英] Convert Byte Array to image in Java - without knowing the type

查看:112
本文介绍了将字节数组转换为Java中的映像 - 不知道类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来很简单吧?使用

ImageIO.read(new ByteArrayInputStream(bytes));

这是皱纹。由于某种原因,它将jpeg检测为bmp,这是我调用时返回的第一个ImageReader

Here's the wrinkle. For some reason it is detecting a jpeg as a bmp, and that is the first ImageReader returned when I call

ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(bytes));
Iterator<ImageReader> readers=ImageIO.getImageReaders(iis);

这会导致图像损坏。有没有办法告诉java没有直接查看标头的字节,并且失败,是否有人知道不同图像的字节标头的良好参考?

This causes the image to come out corrupted. Is there a way to tell through java short of looking directly at the bytes for the header, and failing that does anyone know of a good reference for the byte headers for the different images?

只是让你们知道我还在努力。如果/我有答案,我会通知你。到目前为止,我感谢你们所有人的回复。

Just letting you guys know I am still working on this. I'll let you know if/when I have an answer. I thank all of you for your responses so far.

推荐答案

此页面可能是魔术数字的一个很好的起点。 这里与维基百科类似。

This page might be a good starting point for magic numbers. Here is something similar from Wikipedia.

这篇关于将字节数组转换为Java中的映像 - 不知道类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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