public static Bitmap getImage(String path){
try {
HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
System.out.println("tdw1");
if(conn.getResponseCode() == 200){
InputStream inputStream = conn.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
image.setImageBitmap(getImage("路径"));
public static Bitmap getImage1(String path){
HttpGet get = new HttpGet(path);
HttpClient client = new DefaultHttpClient();
Bitmap pic = null;
try {
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
pic = BitmapFactory.decodeStream(is); // 关键是这句代
} catch (Exception e) {
e.printStackTrace();
}
return pic;
}
public static Uri getImage2(String path,File cacheDir){
File localFile = new File(cacheDir,MD5.getMD5(path)+path.substring(path.lastIndexOf(".")));
if(localFile.exists()){
return Uri.fromFile(localFile);
}else
{
HttpURLConnection conn;
try {
conn = (HttpURLConnection) new URL(path).openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
if(conn.getResponseCode() == 200){
System.out.println("tdw");
FileOutputStream outputStream = new FileOutputStream(localFile);
InputStream inputStream = conn.getInputStream();
byte[] buffer = new byte[1024];
int length = 0;
while((length=inputStream.read(buffer))!=-1){
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
return Uri.fromFile(localFile);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
image.setImageURI(getImage2(path, cache));
cache = new File(Environment.getExternalStorageDirectory(),"cache");
if(!cache.exists()){
cache.mkdirs();
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有