Tar*_*ngh 8 android screenshot google-maps-android-api-2
我正在使用这个答案的代码来截取Google Map v2, 它给出了输出:

哪个可以拍摄Map的屏幕截图
使用以下代码,我可以使用黑色地图屏幕的布局屏幕截图,如下面的代码地图将在ScreenShot中黑色
String mPath = Environment.getExternalStorageDirectory().toString()
+ "/" + "myTestScr" + System.currentTimeMillis() + ".jpeg";
Bitmap bitmap;
View v1 = (View) findViewById(R.id.rootviewtest);
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
File imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
以上代码的输出:

我真正需要的是:

所以,现在我的问题是如何在第3屏幕中获得输出programmatically?
帮我合并两个(1和2)屏幕拍摄一个屏幕截图programmatically?
或者programmatically在拍摄(1和2)屏幕截图后合并两个图像的任何其他替代方案?
JiT*_*HiN 20
调用以下方法以使用地图截取屏幕截图:
public void captureMapScreen() {
SnapshotReadyCallback callback = new SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap snapshot) {
try {
mView.setDrawingCacheEnabled(true);
Bitmap backBitmap = mView.getDrawingCache();
Bitmap bmOverlay = Bitmap.createBitmap(
backBitmap.getWidth(), backBitmap.getHeight(),
backBitmap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(snapshot, new Matrix(), null);
canvas.drawBitmap(backBitmap, 0, 0, null);
FileOutputStream out = new FileOutputStream(
Environment.getExternalStorageDirectory()
+ "/MapScreenShot"
+ System.currentTimeMillis() + ".png");
bmOverlay.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
}
};
mMap.snapshot(callback);
}
Run Code Online (Sandbox Code Playgroud)
mview是您的布局的根视图,mMap是您的地图片段.
确保您拥有最新的Google Play ServicesAPI.
mView.setDrawingCacheEnabled(true);
Bitmap backBitmap = mView.getDrawingCache();
Bitmap bmOverlay = Bitmap.createBitmap(
backBitmap.getWidth(), backBitmap.getHeight(),
backBitmap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(snapshot, new Matrix(), null);
canvas.drawBitmap(backBitmap, 0, 0, null);
Run Code Online (Sandbox Code Playgroud)
snapshot.compress(Bitmap.CompressFormat.PNG, 90, out);如果您只想要地图的屏幕截图,请跳过这些行并使用.
| 归档时间: |
|
| 查看次数: |
5520 次 |
| 最近记录: |