我正在尝试将PNG文件从android服务器发送到python客户端。
我尝试发送的PNG图像是一个屏幕截图,大约4mb,通常低于2mb。在
android代码(发送):
File myFile = new File(imagePath);
FileInputStream fis = null;
try {
fis = new FileInputStream(myFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedInputStream bis = new BufferedInputStream(fis);
Log.i("service", "sending file len");
try {
out.write("" +myFile.length());
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
Log.i("service:", "waiteing for ok");
try {
msg = in.readLine();
} catch (Exception e) {
e.printStackTrace();
}
Log.i("service", "sending file");
byte[] outBuffer = new byte[(int) myFile.length()];
try {
bis.read(outBuffer, 0, outBuffer.length);
os = client.getOutputStream();
os.write(outBuffer, 0, outBuffer.length);
} catch (IOException e) {
e.printStackTrace();
}
python代码(接收):
^{pr2}$文件从android传输到我的电脑,但文件已损坏。
当我将其与原始图像进行比较时,几乎所有内容都是相同的
除了这里和那里的一些空行(不是缺少信息,只是像有人添加的空行)和1或2大块行(15行左右)丢失。
Here您可以看到这些文件之间的比较(左为原始文件,右为发送后的文件)。
我不知道为什么文件传输损坏了,请帮帮我。在
尝试将其编码为Base64并发送一个简单的字符串。那些缺失的行也是图像数据的一部分-记住那些是二进制的。在
Base64或Bytestream是您需要的
相关问题 更多 >
编程相关推荐