I solved this problem. The main issue of this problem is that the MapView class extends View class has "0" value of width and height. (I think every View classes have this issue...)
To set the right size what I want, I extended the MapView to MyMapView and overrided protected onSizeChanged method into MyMapView. And I called that method before saving the map. Then It works! Additionally, I should attach menu button to my app. for saving the map because the loading method of the map is asynchronous as you know.... Saving process is ended before loading the map if the process is in the onCreate method. :) On Aug 21, 9:10 pm, idoun <[email protected]> wrote: > Dear Developers! > > I'm trying to develop a map application which can save some part of > map inside a phone. > > So, refering to the example of google developer site, I created my > activity that using theMapViewclass to display the location what I > want to see. It works. > > And I attached some code to save that view into png format file using > Bitmap and Canvas classes. But it didn't work. > > One image file was created but it didn't contain any information of > the map. I don't know the reason why those codes didn't work and > couldn't find any related information on the Web... > > code is... > > public class AndroidTest extends MapActivity { > > MapViewmapView; > List<Overlay> mapOverlays; > Drawable drawable; > HelloItemizedOverlay itemizedOverlay; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > // build map and mark point > mapView= (MapView) findViewById(R.id.mapview); > mapView.setBuiltInZoomControls(true); > > mapOverlays =mapView.getOverlays(); > drawable = this.getResources().getDrawable > (R.drawable.androidmarker); > itemizedOverlay = new HelloItemizedOverlay(drawable); > > GeoPoint point = new GeoPoint(19240000, -99120000); > OverlayItem overlayitem = new OverlayItem(point, "", ""); > > itemizedOverlay.addOverlay(overlayitem); > mapOverlays.add(itemizedOverlay); > > // copyMapViewto canvas > Bitmap bitmap = Bitmap.createBitmap(400, 800, > Bitmap.Config.ARGB_8888); > Canvas canvas = new Canvas(bitmap); > mapView.draw(canvas); > > // save it! > FileOutputStream fo = null; > > try { > fo = this.openFileOutput("test.png", > Context.MODE_WORLD_WRITEABLE); > } catch (FileNotFoundException e) { > e.printStackTrace(); > } > > bitmap.compress(CompressFormat.PNG, 100, fo); > > try { > fo.flush(); > } catch (IOException e) { > e.printStackTrace(); > } > > try { > fo.close(); > } catch (IOException e) { > e.printStackTrace(); > } > } > > Please, help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

