2 つのボタンと mapView があります。ボタンの 1 つを押したときに MapView のビューを保存したいと考えています。
どうすればこれを行うことができるかについて誰かが考えましたか?
2 つのボタンと mapView があります。ボタンの 1 つを押したときに MapView のビューを保存したいと考えています。
どうすればこれを行うことができるかについて誰かが考えましたか?
このようにOSMDroidを使ってフラグメント画面だけを撮っていました。
private void captureScreen() {
// put captureScreen() inside your OSMDroid fragment
// it's better put a button inside your layout OSMDroid fragment.xml
view = view.findViewById(R.id.mapview); //using OSMDroid fragment to call <org.osmdroid.views.MapView/>
view.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(view.getDrawingCache());
//build your folder
File sd = new File(Environment.getExternalStorageDirectory() + "/ArqueoMaquina");
if (!sd.exists()) {
sd.mkdir();
}
File imagePath = new File(sd , "mapa" + System.currentTimeMillis() + ".png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
Uri uri = Uri.fromFile(imagePath); //to take the file path to your .png map saved in your phone
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
以上が結果です。OSMDroidフラグメントとボタン「マップを保存」を備えた私の画面アプリ:
そして、フォルダー phone に保存された私の map.png には、OSMDroid フラグメントのみが表示されます。