我需要发送图像从安卓应用程序到java应用程序。基本上,我需要一个字节数组从图像发送到射频模块,transmits.Another射频模块接收,并发送字节数组到java应用程序,它必须使图像。
Android代码:
FileInputStream fis = new FileInputStream(myFile);
byte[] b=new byte[(int)myFile.length()];
fis.read(b);server.send(b);Java代码:
FileOutputStream fwrite = new FileOutputStream(new File("my_xml"),true);
fwrite.write(bb);//bb is a byte from rf using input stream as soon as a byte comes it is read to file. This is necessary for some other reasons
fwrite.flush();
fwrite.close();获取完整文件后:
FileInputStream fir=new FileInputStream("my_xml");
final BufferedImage bufferedImage = ImageIO.read(fir);
ImageIO.write(bufferedImage, "bmp", new File("image.bmp"));
fir.close();我收到错误javax.imageio.IIOException:伪造的哈夫曼表格定义rf工作正常,因为文本文件正在发送没有jpeg代码的perfectly.Please help.Even即使在将扩展名改为jpeg之后也不能提供图像
发布于 2012-09-11 16:20:27
该错误表示无法读取图像文件,因为格式为wrong.That,某些字节丢失或错误或位置不正确,因此无法解码文件。我的rf传输没有像tcp/ip这样的协议,因此一些字节由于通信通道中的错误而丢失,从而导致错误。
发布于 2012-09-11 16:39:30
您不需要仅仅为了复制文件而使用ImageIO。只需读写字节即可。
您的代码还存在其他问题:
int。如果是这样,那也没关系。如果没有,你就完蛋了。FileOutputStream。这是最低效的。打开它一次,写下所有的东西,在it.flush()是redundant.close()我们将图像存储在一个叫做'my_xml‘的文件中。这只会引起混淆,如果还没有的话,,
https://stackoverflow.com/questions/12245922
复制相似问题