Alex Rivera | Logout

Android: Canvas vs OpenGL

Asked 2011-06-10T15:26:09.233
18

I have a drawing app where the user can draw lines with their finger, adjust the color, thickness, etc. As the user is drawing, I am converting the massed X/Y points from MotionEvent into SVG Paths, as well as creating Android Path's and then drawing the Android Path's to the screen via a Canvas, and committing the SVG Path's to the app's database.

I am following the model used in FingerPaint, in that the 'in progress' lines are drawn on the fly by repeated calls to invalidate() (and thus, onDraw()), and once the line is complete and a new line is started, the previous line(s) are drawn in onDraw() from the underlying Canvas Bitmap, with in progress lines again generating repeated re-draws.

This works fine in this application - until you start rotating the underlying Bitmap to compensate for device rotation, supporting the ability to 'zoom in' on the drawing surface and thus having to scale the underlying Bitmap, etc. So for example, with the device rotated and the drawing scaled in, when the user is drawing, we need to scale AND rotate our Bitmap in onDraw(), and this is absolutely crawling.

I've looked at a SurfaceView, but as this still uses the same Canvas mechanism, I'm not sure I'll see noticeable improvement... so my thoughts turn to OpenGL. I have read somewhere that OpenGL can do rotations and scaling essentially 'for free', and even seen rumors (third comment) that Canvas may be disappearing i

Edit
Report

1 Answer

6

OpenGL would be able to handle the rotations and scaling easily.

Honestly, you would probably need to learn a lot of OpenGL to do this, specifically related to the topics of:

  • Geometry
  • Lighting (or just disabling it)
  • Picking (selecting geometry to draw on it)
  • Pixel Maps
  • Texture Mapping
  • Mipmapping

Also, learning OpenGL for this might be overkill, and you would have to be pretty good at it to make it efficient.

Instead, I would recommend using the graphic components of a game library built on top of openGL, such as:

answered 2011-06-10T17:04:13.353

Your Answer