百度地图SnapshotReadyCallback截屏

今天碰到了地图截图的功能,不太会,查查资料知道怎么弄了,跟大家分享一下

直接上代码,弄了一个方法,将截取的图片上传至服务器,返回给我们图片路径

 1 //获取地图截图
 2     private void getscreenshot() {
 3         mBaiduMap.snapshot(new BaiduMap.SnapshotReadyCallback() {
 4             @Override
 5             public void onSnapshotReady(Bitmap bitmap) {
 6                 File file = new File("/mnt/sdcard/kuaikan.png");
 7                 FileOutputStream out;
 8                 try {
 9                     out = new FileOutputStream(file);
10                     if (bitmap.compress(
11                             Bitmap.CompressFormat.PNG, 100, out)) {
12                         out.flush();
13                         out.close();
14                         upFile(file);
15                     }
16                 } catch (Exception e) {
17                     e.printStackTrace();
18                 }
19 
20             }
21         });
22     }
23 
24     private void upFile(File file) {
25         long size = file.length() / 1024;
26         size = size / 1024;
27         if (size > 2) {
28             showCustomToast("请上传2M以内的图片!");
29             return;
30         }
31         EGRequestParams para = new EGRequestParams();
32         para.addBodyParameter("fileName", file);
33         para.addBodyParameter("isCompress", false + "");
34         HttpUtil.post(this, UrlConfig.UP_LOAD_FILE, para, new HttpUtil.Ok() {
35             @Override
36             public void success(String str) {
37                 screenshot = str;//服务器返回给我们的路径
38             }
39 
40             @Override
41             public void complete(String str) {
42 
43             }
44         });
45     }

拿到路径,我们就可以上传数据,然后获取数据,根据路径显示图片了,就是百度截图的图片,哈哈,看起来很简单的!

原文地址:https://www.cnblogs.com/wangying222/p/6016523.html