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?

2
  • try to change Config.ARGB_4444 to Config.ARGB_8888 Commented Aug 23, 2013 at 5:39
  • It's still not working. Commented Aug 23, 2013 at 5:42

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

9 Comments

You mean to say I should use Mapview's height and width for the temporary canvas?
If this is the size you need, then yes.
Nah, it's still not working. I can't figure out what I'm doing wrong here.
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.
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);
|
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"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.