【发布时间】:2015-01-28 17:39:11
【问题描述】:
大家好,我在 Eclipse 上以编程方式截屏,它成功了,但谷歌地图片段只在我的截屏结果中显示黑页。我应该怎么做才能在我的屏幕截图上显示地图?
这是我的代码:
public void download (View v){
View view = findViewById(R.id.layout_id);
view.setDrawingCacheEnabled(true);
Bitmap bitmap = view.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);
//ImageView iv = (ImageView) findViewById(R.id.imageView1);
FrameLayout iv = (FrameLayout)findViewById(R.id.map);
//iv.setBackgroundDrawable(bitmapDrawable);
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
//we check if external storage is available, otherwise display an error message to the user
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard.getAbsolutePath() + "/Transit_Guide_Downloads");
directory.mkdirs();
String filename = "download_" + i + ".jpg";
File yourFile = new File(directory, filename);
while (yourFile.exists()) {
i++;
filename = "download_" + i + ".jpg";
yourFile = new File(directory, filename);
}
if (!yourFile.exists()){
if (directory.canWrite())
{
try {
FileOutputStream out = new FileOutputStream(yourFile, true);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
out.flush();
out.close();
Toast.makeText(SecondMap.this, "File exported to /sdcard/Transit_Guide_Downloads/screenshot" + i + ".jpg", Toast.LENGTH_SHORT).show();
i++;
} catch (IOException e) {
e.printStackTrace();
}
}
}}
else
{
Toast.makeText(SecondMap.this, "SD Card not available!", Toast.LENGTH_SHORT).show();
}
}
【问题讨论】:
-
您在哪里获取屏幕截图,是在模拟器上还是在真实设备上?因为我检查了我的设备,所以它工作正常。
-
在我的物理设备上,程序可以运行,但地图片段只是黑色,没有显示地图。
标签: android eclipse google-maps screenshot screen-capture