举例:android从apache服务器获取文件(图像),保存到相应的目录中,并从目录中将图像转变为Bitmap

 /* * 参数 :将要获取的服务器文件名 filename * 如果成功,返回真*/boolean getImageByWeb2(String filename) {     File img = new File(TEMP_WEB_IMAGE_PATH + filename);     // Create directories     new File(TEMP_WEB_IMAGE_PATH).mkdirs();    // only download new images     if (!img.exists()) {         try {             URL imageUrl = new URL("http://10.10.145.154/WebImageProcess/output/" + filename);             InputStream in = imageUrl.openStream();             OutputStream out = new BufferedOutputStream(new FileOutputStream(img));              for (int b; (b = in.read()) != -1;) {                 out.write(b);             }             out.close();             in.close();         } catch (MalformedURLException e) {             img = null;            return false;         } catch (IOException e) {             img = null;            return false;         }     }     return true; }


调用:

if(getImageByWeb2("processed_"+serverFileName)){    //将保存完毕的图像,转变为Bitmap格式    Bitmap resultForWebImage=FilesToBitmap(TEMP_WEB_IMAGE_PATH+"processed_"+serverFileName);}


附属代码:

private static final String TEMP_WEB_IMAGE_PATH="/sdcard/app/tmp/";Bitmap FilesToBitmap(String filename){    Bitmap temp=null;    if(filename!=null){        File imageFile = new File(filename);            if (imageFile.exists())            {            // Load the image from file            temp = BitmapFactory.decodeFile(filename);            }            }    return temp;}


转载请声明:http://blog.csdn.net/nuptboyzhb/article/details/7983318

更多相关文章

  1. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  2. android 中的 Bitmap 相关
  3. android camera(一):camera模组CMM介绍
  4. Android(安卓)关于获取摄像头帧数据
  5. Android流量监控
  6. activity状态的保存和保持(onRetainNonConfigurationInstance和g
  7. Android中使用Gson解析JSON数据
  8. Android中使用Gson解析JSON数据
  9. Android保存32位BMP格式图片

随机推荐

  1. 大型团队 Jenkins 实践分享
  2. 何勉:第一性原理和精益敏捷的规模化实施
  3. 预生产环境数量的统计和分析
  4. CONUTIF函数经典用法,全了
  5. 一看就会,一用就废?八个实用技巧请拿好
  6. 五个常用公式,效率提高一点点
  7. 五分钟,学会一对多、多对多查询经典公式
  8. DevSecOps 三问:Why?What?How?
  9. 一对多、多对多查询,最简单的方法请拿好
  10. C数组实现静态链表及常用操作(模拟无指针