7

I am wondering if there is a way to draw filled areas (like a filled polygon) with the Android Canvas without using the Path class and call canvas.drawPath(...).

The reason I want to do this without Path is because I have to draw very large datasets and canvas.drawPath(...) is not hardware accelerated and therefore slow.

The performance when using canvas.drawLines(...) is much better because of hardware acceleration, however I have not found a way to draw the polygon filled using this approach (even when the lines are all connected).

Even calling paint.setStyle(Style.FILL) did not fill the polygon when using drawLines(...).

Is there a way to draw a filled-polygon without using the Path approach?

Or is there any other way to improve performance using the Canvas?

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
  • Is your `view` interactive (do you have changes to your dataset on the fly that need to be rendered)? Simply drawing your dataset to the `canvas` once is slow? – tato.rodrigo Mar 16 '15 at 20:56
  • My View is interactive and therefore constantly refreshed, I am already using a buffering mechanism, which greatly improved performance. However, I am not satisfied yet. – Philipp Jahoda Mar 16 '15 at 20:58
  • My last question to elaborate an answer. When a change occurs to your dataset are you drawing the whole dataset again or just the ones affected in the area of change? I mean, are you already using the `view.invalidate(Rect dirty)`? This is just a tip to improve the performance. – tato.rodrigo Mar 17 '15 at 11:36
  • That's actually a very good idea. But I think it cannot be used in my case since I'm drawing a chart and when it is e.g. zoomed in and scrolled, the whole view needs to be refreshed. – Philipp Jahoda Mar 17 '15 at 11:48
  • Do you want to start a conversation? I worked on android drawing app and had some issues like this. I can share some of my "know-how" if you want. – tato.rodrigo Mar 17 '15 at 11:52
  • Sure, would be great :-) – Philipp Jahoda Mar 17 '15 at 11:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/73157/discussion-between-tato-rodrigo-and-philipp-jahoda). – tato.rodrigo Mar 17 '15 at 11:52

2 Answers2

0

You might want to look at opengl view and use it for all the drawings you need. Definitely will be damn fast. Still, all your drawing code needs to be re-written.

Cynichniy Bandera
  • 5,991
  • 2
  • 29
  • 33
0

You probably need to do something like :

Paint red = new Paint();

red.setColor(android.graphics.Color.RED);
red.setStyle(Paint.Style.FILL);

And use this color for your path, instead of your ARGB. Make sure the last point of your path ends on the first one, it makes sense also.

Hemant Ramphul
  • 565
  • 5
  • 8