views:

706

answers:

1

Is there another way to draw an object on a canvas in android?

This code inside draw() doesn't work:

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pushpin);            
         canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);  

Well actually, it's working on my 1st code but when I've transfered this to another class called MarkOverlay, it's not working anymore.

  markerOverlay = new MarkerOverlay(getApplicationContext(), p);
                      listOfOverlays.add(markerOverlay);  

What parameter should I pass to MarkerOverlay to make this code work? The error is somewhere in getResources().

FYI, canvas.drawOval is perfectly working but I really want to draw an Image not an Oval. :)

+1  A: 

Override the 'draw' method in the MarkerOverlay class. I assume you have derived MarkerOverlay from Overlay. See an example here.

Maurits Rijk
Thank you for that sample code. I saw my mistake. It should be context.getResources() not just getResources().
lulala