举例: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图像处理系统1.3
  2. Android 加载服务器上的图片
  3. android 获取网络上服务器图片
  4. Android与php服务器交互实例
  5. Android设置背景图像重复【整理自网络】
  6. android SDK升级连接不上服务器解决方案
  7. Android Studio3.3.2 +OpenCV3.4.3图像处理
  8. Android上传文件到Web服务器,PHP接收文件(二)
  9. Android图像处理相关文章

随机推荐

  1. Android编程心得---ViewPager+Fragment篇
  2. android项目中的功能清单文件
  3. activity 监听手势滑动 上下左右
  4. Android 显示网络信息 ConnectivityManag
  5. 基于axis2的webservice和android简单的本
  6. Android 调用系统的拨号服务实现 电话拨
  7. Frame-By-Frame Animations的使用方法
  8. Handler、Message、MessageQueue、Looper
  9. android project bug
  10. Android下DrawerLayout的使用