android - 应用截图?
问题描述
我有一个 Google Map Android 应用程序,我尝试将整个视图的屏幕截图与地图一起捕获。截取了屏幕截图,但谷歌地图全黑,只有谷歌标志。我使用以下代码:
private void captureScreen() {
View v = getWindow().getDecorView().getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
try {
FileOutputStream fos = new FileOutputStream(new File(Environment
.getExternalStorageDirectory().toString(), "SCREEN"
+ System.currentTimeMillis() + ".png"));
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/mapLayout">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
tools:context="net.aratos.adc.MapActivity"
android:layout_height="0dp"
android:layout_weight="0.8"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.1"
android:layout_gravity="center_horizontal">
<Button
android:gravity="center"
android:id="@+id/loadDateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load date" />
<Button
android:gravity="center"
android:id="@+id/snapshotButton"
android:text="Snapshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:gravity="center"
android:id="@+id/exportButton"
android:text="Export PDF"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<GridView
android:orientation="horizontal"
android:id="@+id/boundsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="auto_fit">
</GridView>
</LinearLayout>
我还附上了布局的代码。输出截图如下 图
尝试 Brijesh 的代码后,我得到以下输出
解决方案
您可以使用 GoogleMap.snapshot 方法拍摄地图的快照(文档)
您将需要实施一个
管理拍摄的快照。
另外,请考虑到,根据文档:
注意: 地图的图像不得传输到您的服务器,或以其他方式在应用程序之外使用。如果您需要将地图发送给另一个应用程序或用户,请发送允许他们为新用户重建地图而不是快照的数据。
推荐阅读
- python - 带有两个数据框的 Pandas 矢量化
- java - 更改为夜间模式会复制回收站视图中的项目
- vue.js - 如何使用 Animejs 绘制 SVG 和动画
- git - git分支历史没有更新
- node.js - 使用文档中的属性值在使用 mongoose 的查找查询中访问另一个文档的属性
- c# - IsMouseOver 未触发按钮
- blazor - 在窗口调整大小时触发 Blazor 事件
- php - Cakephp如何从管理文件夹设置根页面?
- javascript - 为什么我的 formdata POST 没有被 Cors 政策阻止?
- amazon-web-services - AWS - 这可能吗?- 通过 ip 重定向到不同的 index.html 页面-