Android Canvas Example

Problems with Canvas, OpenGL, etc...

Android Canvas Example

Postby james.liu » Sat Apr 30, 2011 7:20 pm

Android provide a full functions on Graphics. Commonly, we can use 2D graphics library and OpenGL ES 1.0 for 3D graphic. In this post, I gonna to introduce the 2D graphics, and give you a 2D graphics canvas example.

Usually, when we try to draw 2D graphics, as android developer page say, we have two ways to choose:

  1. Draw your graphics or animations into a View object from your layout.
  2. Draw your graphics directly to a Canvas.

Draw graphics directly to a Canvas is a little bit complicated. You can go to the android developer page for farther details. The following example will show you how to draw a bitmap on the canvas, when you click the canvas.

As android dev guide says, when you’re writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a Canvas. When we do so, we will put our drawing code in onDrwa() callback method, and Canvas will be pass from the function parameter. And we also can get a canvas by calling SurfaceHolder.lockCanvas();

Here is a code example, apk file and source code:

Android Canvas Example

Hopeful, it will be helpful.
Posts: 5
Joined: Wed Apr 20, 2011 9:09 am


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest