Android Canvas Example

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 15

Apr 30, 2011, 8:24:59 PM via Website

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.

— modified on May 1, 2011, 2:46:23 PM

Recommended by NextPit