通过URl将服务器的图片下载到本地并压缩
private void downloadServerPic(final String url1) {
new Thread() {
@Override
public void run() {
// 定义一个URL对象
URL url;
try {
url = new URL(url1);
// 打开该URL的资源输入流
InputStream is = url.openStream();
is.close();
// 再次打开RL对应的资源输入流
is = url.openStream();
//创建输出流
FileOutputStream outStream = null;
try {
byte[] bary = readInputStream(is);
File imageFile = new File( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");
outStream = new FileOutputStream(imageFile);
//写入数据
outStream.write(bary);
//getimage 方法见 http://www.cnblogs.com/wangzehuaw/p/4447120.html
bitMap = getimage( Environment.getExternalStorageDirectory() + "/DCIM/UxinUsedCar/"+"share.jpg");
//关闭输出流
} catch (Exception e) {
e.printStackTrace();
} finally {
if(outStream != null)
outStream.close();
is.close();
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。