1

I have to draw a line on the map. Due to the requirement of special line effects, I had to create a separate bitmap and draw lines on that bitmap, using a temporary canvas. Now When it completes drawing lines, I render it to the main canvas. Unfortunately, the below code is not working for me.

  @Override
    protected void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
    Bitmap pathBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Config.ARGB_4444);
    Canvas tempCanvas = new Canvas(pathBitmap);
    tempCanvas.drawPath(mPath, this.mPaint);
    canvas.drawBitmap(pathBitmap, 0, 0, null);
    }

Could anyone please tell me what I'm doing wrong here?

Update: To see what I'm doing wrong. I created a new class and extended it with Drawable. In that class, I override the Draw method and used the same code with only parameter Canvas, and it worked. But don't know why it's not working on the MapView. Anyone please help me out?

user1294668
  • 163
  • 1
  • 3
  • 12

2 Answers2

1

You should rather use view's getWidget() and getHeight() instead of taking size of the canvas when creating a bitmap.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86
  • You mean to say I should use Mapview's height and width for the temporary canvas? – user1294668 Aug 23 '13 at 05:45
  • If this is the size you need, then yes. – sergej shafarenka Aug 23 '13 at 05:48
  • Nah, it's still not working. I can't figure out what I'm doing wrong here. – user1294668 Aug 23 '13 at 05:51
  • Here is a "make sure" checklist: width and height are not 0, path is not empty, paint is configured to have a different color than canvas' background and it is of STROKE type with stroke width > 0. The code itself is correct. – sergej shafarenka Aug 23 '13 at 05:54
  • Checked everything. width and height are 600 X 966. Here's the Paint object. Path is not empty. Paint() mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(color); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(6.0f); – user1294668 Aug 23 '13 at 06:11
  • The issue is somewhere else, not in this code. I don't see you use `mapView` in the code snippet. How do you use it? – sergej shafarenka Aug 23 '13 at 07:22
  • I'm using OSM Maps. I created a Customclass, extends Overlay, that is used to draw a path. I create an instance of this class and use it in the Activity class where MapView is being displayed. Then, I add the Customclass object to MapView using mapview.getoverlays().add(customclass object). – user1294668 Aug 23 '13 at 07:33
  • (Continue) I can draw lines (without the special effects) on the MapView. But due to the requirement of the special effects, I had to create a seperate bitmap and draw the line on that bitmap using temporary canvas. Here's the reference link I get the code from. Please have a look at that link. http://stackoverflow.com/questions/10907386/custom-path-line-style-when-drawing-on-canvas – user1294668 Aug 23 '13 at 07:34
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36078/discussion-between-user1294668-and-beworker) – user1294668 Aug 23 '13 at 07:37
0

I struggled with a similar issue. Eventually I looked at the console window and found this warning:

"OpenGLRenderer: Bitmap too large to be uploaded into a texture". Could that be your problem? See "Bitmap too large to be uploaded into a texture"

Tim Cooper
  • 10,023
  • 5
  • 61
  • 77