举例: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. Android打开通讯录并获取数据
  2. 2011.09.26(3)——— android sample之Notepad(带下划线的TestView
  3. 面试例题6:两种方法将图像显示在View上
  4. Android常用方法——获取系统信息
  5. android xml
  6. android获取手机型号和系统版本号
  7. Android(安卓)HorizontalScrollView 水平滑动 在listview上面动
  8. Android(安卓)使用Gallery仿3D画廊效果实现
  9. Android媒体文件metadata是如何实现跟解码器结合获取的

随机推荐

  1. Appcelerator Cloud Push Notification i
  2. EditText去掉边框和隐藏光标
  3. android中表格绘图
  4. android进度条对话框小例子
  5. Android(安卓)CoordinatorLayout的使用—
  6. Android(安卓)PromptDialog example
  7. android 隐藏输入法
  8. Android根据URL下载文件保存到SD卡
  9. Android传感器使用
  10. Linaro android media create BUG