关键词: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. android 通过资源文件名称获取资源文件id
  2. [android]android命令行截图
  3. Android Studio 3.0以后打包修改文件名方法
  4. android webview 截图快照
  5. Android Studio设置apk文件名
  6. android Gradle打包修改生成的apk文件名称
  7. Android 屏幕截图并用WindowManager显示
  8. 微软的 Android 计划:邪恶的天才计划或只是邪恶?

随机推荐

  1. android utf-8 显示韩文的小坑 && 小技巧
  2. 雷电android game学习笔记(1)
  3. UE4 安卓打包纹理格式选择
  4. [Android笔记] 关于 AppWidget 动态更新:R
  5. [Android设计模式]Android退出应用程序终
  6. android SlidingDrawer(抽屉)
  7. Android(安卓)“adb”不是内部或外部命令
  8. Android与服务器端数据交互
  9. android 编译自己的sdk
  10. [译] 在 Android 使用协程(part III) -