render my map (file PNG or JPG) on MapView make trouble

Put your problem here if it does not fit any of the other categories.

render my map (file PNG or JPG) on MapView make trouble

Postby tsdt » Mon Mar 17, 2008 4:53 am

Hi friends!
I 'm rendering my map file "map.PNG"(or "map.JPG") on MapView with code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package android.asnet.tttttt;
  3.  
  4. import com.google.android.maps.MapActivity;
  5.  
  6. import com.google.android.maps.MapController;
  7.  
  8. import com.google.android.maps.MapView;
  9.  
  10. import com.google.android.maps.Overlay;
  11.  
  12. import com.google.android.maps.OverlayController;
  13.  
  14. import com.google.android.maps.Overlay.PixelCalculator;
  15.  
  16.  
  17.  
  18. import android.app.Activity;
  19.  
  20. import android.content.Context;
  21.  
  22. import android.graphics.Bitmap;
  23.  
  24. import android.graphics.BitmapFactory;
  25.  
  26. import android.graphics.Canvas;
  27.  
  28. import android.graphics.Paint;
  29.  
  30. import android.os.Bundle;
  31.  
  32. public class tttttt extends MapActivity {
  33.  
  34.         MyOverlay myOverlay;
  35.  
  36.         MapController myMapController;
  37.  
  38.         MapView myMapView;
  39.  
  40.         OverlayController myOverlayController;
  41.  
  42.     @Override
  43.  
  44.     public void onCreate(Bundle icicle) {
  45.  
  46.         super.onCreate(icicle);
  47.  
  48.         myMapView=new MapView(this);
  49.  
  50.         setContentView(myMapView);
  51.  
  52.         myMapController=myMapView.getController();
  53.  
  54.         myOverlayController=myMapView.createOverlayController();
  55.  
  56.         myOverlay =new MyOverlay(this);
  57.  
  58.         myOverlayController.add(myOverlay, true);
  59.  
  60.        
  61.  
  62.     }
  63.  
  64.     class MyOverlay extends Overlay
  65.  
  66.     {
  67.  
  68.         Bitmap myBitmap;
  69.  
  70.         Paint myPaint;
  71.  
  72.         public void onDraw(Canvas canvas, PixelCalculator calculator, boolean shadow)
  73.  
  74.         {
  75.  
  76.                 super.draw(canvas,calculator,shadow);
  77.  
  78.                 canvas.drawBitmap(myBitmap, 10, 10, myPaint);
  79.  
  80.         }
  81.  
  82.         public MyOverlay(Context context)
  83.  
  84.         {
  85.  
  86. //              giai ma hinh anh "map" dua vao Resource va giai ma Resource de coi bang Bitmap
  87.  
  88.                 myBitmap=BitmapFactory.decodeResource(context.getResources(),R.drawable.map);
  89.  
  90.                 myPaint=new Paint();
  91.  
  92.                 BitmapFactory.Options opts = new BitmapFactory.Options();
  93.  
  94.                 opts.inJustDecodeBounds = false;    // this will request the bm
  95.  
  96.             opts.inSampleSize = 16;             // scaled down by 16 times
  97.  
  98.         }
  99.  
  100.     }
  101.  
  102. }
  103.  
  104.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4

But the screen do not show anything but blank, please help me!
Thanks!
TSDT.
TSDT
tsdt
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Jan 09, 2008 4:20 am
Location: VIETNAM

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests