android怎么在服务器和客户端之间传输图片? 15
这是我的服务端的代码:StringimagePath="/home/shenlei/tupian/jiaofu.jpg";Filefile=newFile(imagePa...
这是我的服务端的代码:
String imagePath="/home/shenlei/tupian/jiaofu.jpg";
File file =new File(imagePath);
FileInputStream inputstream = new FileInputStream(file);
OutputStream out = resp.getOutputStream();
//拷贝输出
byte[] buf = new byte[1024];
int count = 0;
while ((count =inputstream.read(buf)) >= 0) {
out.write(buf, 0, count);
}
inputstream.close();
out.close();
}
这是客户端的接受的代码:
// 取得图片字节流
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
bitmap = BitmapFactory.decodeStream(is);
is.close();
但是获取的图像没有现实出来:
ImageView image = (ImageView) findViewById(R.id.detail_img);
image.setImageBitmap(HttpUtil.bitmap);
这是log
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo-, SUCCESS
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo-, SUCCESS
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo-, SUCCESS
07-28 12:52:13.871: I/global(25884): call createSocket() return a new socket.
07-28 12:52:13.871: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.871: D/libc(25884): [NET] getaddrinfo-, SUCCESS 展开
String imagePath="/home/shenlei/tupian/jiaofu.jpg";
File file =new File(imagePath);
FileInputStream inputstream = new FileInputStream(file);
OutputStream out = resp.getOutputStream();
//拷贝输出
byte[] buf = new byte[1024];
int count = 0;
while ((count =inputstream.read(buf)) >= 0) {
out.write(buf, 0, count);
}
inputstream.close();
out.close();
}
这是客户端的接受的代码:
// 取得图片字节流
HttpEntity httpEntity = response.getEntity();
InputStream is = httpEntity.getContent();
bitmap = BitmapFactory.decodeStream(is);
is.close();
但是获取的图像没有现实出来:
ImageView image = (ImageView) findViewById(R.id.detail_img);
image.setImageBitmap(HttpUtil.bitmap);
这是log
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo-, SUCCESS
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo-, SUCCESS
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.861: D/libc(25884): [NET] getaddrinfo-, SUCCESS
07-28 12:52:13.871: I/global(25884): call createSocket() return a new socket.
07-28 12:52:13.871: D/libc(25884): [NET] getaddrinfo+,hn 13(0x3139322e313638),sn(),family 0,flags 4
07-28 12:52:13.871: D/libc(25884): [NET] getaddrinfo-, SUCCESS 展开
7个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |