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

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

 //获取地图截图
private void getscreenshot() {
mBaiduMap.snapshot(new BaiduMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap bitmap) {
File file = new File("/mnt/sdcard/kuaikan.png");
FileOutputStream out;
try {
out = new FileOutputStream(file);
if (bitmap.compress(
Bitmap.CompressFormat.PNG, 100, out)) {
out.flush();
out.close();
upFile(file);
}
} catch (Exception e) {
e.printStackTrace();
} }
});
} private void upFile(File file) {
long size = file.length() / 1024;
size = size / 1024;
if (size > 2) {
showCustomToast("请上传2M以内的图片!");
return;
}
EGRequestParams para = new EGRequestParams();
para.addBodyParameter("fileName", file);
para.addBodyParameter("isCompress", false + "");
HttpUtil.post(this, UrlConfig.UP_LOAD_FILE, para, new HttpUtil.Ok() {
@Override
public void success(String str) {
screenshot = str;//服务器返回给我们的路径
} @Override
public void complete(String str) { }
});
}

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

05-22 00:36