关键词:arcgis for android ,截图,bitmap,sd卡

参考文章:http://blog.csdn.net/wozaifeiyang0/article/details/7679727

在arcgis for android地图中mapview加入截图功能。

参考上文,将mapview转化为bitmap。代码如下:

 1 private Bitmap getViewBitmap(MapView v) { 2         v.clearFocus(); 3         v.setPressed(false); 4  5         //能画缓存就返回false 6         boolean willNotCache = v.willNotCacheDrawing(); 7         v.setWillNotCacheDrawing(false);  8         int color = v.getDrawingCacheBackgroundColor(); 9         v.setDrawingCacheBackgroundColor(0);10         if (color != 0) {11             v.destroyDrawingCache();12         }13         v.buildDrawingCache();14         Bitmap cacheBitmap = null;15         while(cacheBitmap == null){16          cacheBitmap = v.getDrawingMapCache(0, 0, v.getWidth(), v.getHeight());17         }18         Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);19         // Restore the view20         v.destroyDrawingCache();21         v.setWillNotCacheDrawing(willNotCache);22         v.setDrawingCacheBackgroundColor(color);23         return bitmap;24     }

然后处理存储的文件名以及保存到sd卡,此处采用日期加时间存储,精确到秒。

为了防止一秒内多次点击,文件名被占用,代码中加入了处理(虽然出现的概率比较小,但也是可能存在的。。。)。

 1 private void mapviewshot() { 2         System.out.println("进入截屏方法"); 3         Date date=new Date(); 4         SimpleDateFormat dateformat1=new SimpleDateFormat("yyyyMMdd_hhmmss"); 5         String timeString=dateformat1.format(date); 6         String path="arcgis1/screenshot"; 7         String externalPath=Environment.getExternalStorageDirectory().toString(); 8         String filename=externalPath+"/"+path+"/"+timeString; 9         10         File file_2=new File(externalPath+"/"+path);11         if (!file_2.exists()){12             System.out.println("path 文件夹 不存在--开始创建");13             file_2.mkdirs();14         }15         filename=getfilepath(filename);//判断是否有同一秒内的截图,有就改名字16         //存储于sd卡上17         System.out.println("获得的filename--"+filename);18         Bitmap bitmap=getViewBitmap(mMapView);19         20         File file=new File(filename);    21         try {22             FileOutputStream fileOutputStream=new FileOutputStream(file);23             bitmap.compress(Bitmap.CompressFormat.PNG, 90, fileOutputStream);24             fileOutputStream.flush();25             fileOutputStream.close();26         } catch (FileNotFoundException e) {27             e.printStackTrace();28         } catch (IOException e) {29             e.printStackTrace();30         }31         32         33     }34     private String getfilepath(String filename) {35         String filestr=filename+".png";36         File file=new File(filestr);37         if (file.exists()){38             filename=getfilepath(filename+"_1");39         }40         else {41             filename=filestr;42         }43         System.out.println("getfilename函数返回----"+filename);44         return filename;45     }

还可以处理的是加入命名的对话框,实现自由命名。textview固定文件夹路径,提供textfield供用户命名,然后保存。

更多相关文章

  1. Activity-Spinner使用
  2. 一些非常实用的 Android(安卓)开发资源 【转】
  3. Android(安卓)分享功能
  4. android 3.0以上对usb设备的访问USB
  5. Shape属性详解
  6. Android自学笔记(番外篇):全面搭建Linux环境(四)——JDK的安装与卸载(
  7. android屏幕截图
  8. ch029 Android(安卓)service aidl
  9. android 开源项目汇总

随机推荐

  1. android源码学习之animation1
  2. Android(安卓)xml资源文件中@、@android:
  3. Android相对布局RelativeLayout各属性介
  4. Android(安卓)TextView 文字居中
  5. Android:控件样式触发
  6. Android系统自带样式(@android:style/)
  7. Android中TextView中加图片,超链接,部分字
  8. Android(安卓)EditText inputType同时设
  9. Android:布局(相对布局RelativeLayout)
  10. android 杂疑汇总