SoFunction
Updated on 2025-04-07

Android arcgis sample code to save Mapview as picture

I won’t say much nonsense, I will just post the code to you. The specific code is as follows:

/**
 * Convert a View object into a bitmap
 */
private Bitmap getViewBitmap(MapView v) {
();
(false);
//Return false if you can draw cacheboolean willNotCache = ();
(false);
int color = ();
(0);
if (color != 0) {
();
}
();
Bitmap cacheBitmap = null;
while(cacheBitmap == null){
cacheBitmap = (0, 0, (), ());
}
Bitmap bitmap = (cacheBitmap);
// Restore the view
();
(willNotCache);
(color);
return bitmap;
}
public void saveMyBitmap(String bitName,Bitmap mBitmap){
String FileName=() + "/" + bitName + ".png";
ShowMessage(FileName);
File f = new File(FileName);
try {
();
} catch (IOException e) {
// TODO Auto-generated catch block
("Save"+FileName+"An error occurred in picture:" + (),"Save"+FileName+"An error occurred in picture:" + ());
}
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
();
}
(, 100, fOut);
try {
();
} catch (IOException e) {
();
}
try {
();
} catch (IOException e) {
();
}
}
//Shrinkprivate class ButtonNexitClickListener implements  {
public void onClick(View v) {
//ShowMessage("ok1");
Bitmap bitmap=getViewBitmap(mapView);
//ShowMessage("ok2");
saveMyBitmap("yl",bitmap);
//ShowMessage("ok3");
();
ShowMessage("Save successfully");
}
}

The above is the example code for saving Mapview as a picture by the editor, I hope it will be helpful to everyone!