40 likes | 180 Views
Graphics in Android. Canvas. Class android.graphics.Canvas represents a surface on which to draw Some of the useful drawing methods drawArc draws an arc of a circle. Can be used for 'pie segments' as well. drawBitmap draws an image represented as a bitmap drawCircle drawOval
E N D
Graphics in Android Fall 2012 CS2302: Programming Principles
Canvas • Class android.graphics.Canvas represents a surface on which to draw • Some of the useful drawing methods • drawArc draws an arc of a circle. Can be used for 'pie segments' as well. • drawBitmap draws an image represented as a bitmap • drawCircle • drawOval • drawRect • drawText • drawColor fills the background of the canvas with a color Fall 2012 CS2302: Programming Principles
Path • A Pathcan, for example, be used to build up a polygon. • A path is understood as being drawn by a pen. When the pen is touching the drawing surface, a visible trace is left. However, the pen can also be moved without leaving a visible mark. • At any stage during the construction of a path, there is a current point. This is the current position of the pen. • The lineTo moves the pen to a new point, drawing a straight line from the previous current point to the point given by the parameters to the method call. The end point of the line becomes the new current point. • By contrast, the moveTo method moves the pen, changing the current point, but does not leave a trace. The path should begin with a moveTo call so that the path can start at a well determined position. • The close adds a line segment from the current point back to the first point on the path. This signals that the path is closed and, therefore, can be filled with color. Fall 2012 CS2302: Programming Principles
Paint • In Android, the android.graphics.Paintclass is used to contain many details of how drawing should be done. Most drawing methods require a Paint object be provided as an argument. • The color of the drawing is one property. • The style property is specified by a value of class Paint.Style. The three values specify whether the shape is to be outlined, filled or both filled and outlined. Fall 2012 CS2302: Programming Principles