Android Programming Press on the image to return to the main documentation page.

Drawing (Core)

List of types:

Bitmap
Canvas
Path
Rect

Bitmap

An object that holds an image. You can use ImageView to show an image.

Events:

None

Members:


  Height As Float [read only]

  Initialize (Dir As String, FileName As String)

  Initialize2 (InputStream As InputStream)

  IsInitialized As Boolean

  Tag As Object

  Width As Float [read only]

  WriteToStream (OutputStream As OutputStream, Quality As Int, Format As String)

Members description:

Height As Float [read only]
Returns the bitmap height.
Initialize (Dir As String, FileName As String)
Loads the specified image. If the image name ends with @2x (without the extension) then the image scale is considered to be 2.
If you load an image named image1.png. And in the same folder there is also an image named [email protected] then on a high resolution device
[email protected] will be loaded and the image scale will be set to 2.
Initialize2 (InputStream As InputStream)
Reads a bitmap from the input stream.
IsInitialized As Boolean
Tests whether this object was initialized.
Tag As Object
Gets or sets the Tag object. This is a placeholder for any object you like to tie to this object.
Width As Float [read only]
Returns the bitmap width.
WriteToStream (OutputStream As OutputStream, Quality As Int, Format As String)
Writes the image to the output stream.
Quality - Value between 0 (smaller size, lower quality) to 100 (larger size, higher quality).
Format - JPEG or PNG.

Canvas

Canvas is used for drawing over other views.
The drawings will only be updated after a call to Canvas.Refresh. Note that you should call Canvas.Release when it is no longer used.
If the hosting is resized then the canvas should be released and initialized again.

Events:

None

Members:


  ClipPath (Path As Path)

  CreateBitmap As Bitmap

  DrawBitmap (Bitmap As Bitmap, DestRect As Rect)

  DrawBitmapRotated (Bitmap As Bitmap, DestRect As Rect, Degrees As Float)

  DrawCircle (x As Float, y As Float, Radius As Float, Color As Int, Filled As Boolean, StrokeWidth As Float)

  DrawColor (Color As Int)

  DrawLine (x1 As Float, y1 As Float, x2 As Float, y2 As Float, Color As Int, StrokeWidth As Float)

  DrawPath (Path As Object, Color As Int, Filled As Boolean, StrokeWidth As Float)

  DrawPDF (Document As PDFDocument, PageNumber As Int, DestRect As Rect)

  DrawRect (Rect1 As Rect, Color As Int, Filled As Boolean, StrokeWidth As Float)

  DrawRectRotated (Rect1 As Rect, Color As Int, Filled As Boolean, StrokeWidth As Float, CornersRadius As Float, Degrees As Float)

  DrawRectRounded (Rect1 As Rect, Color As Int, Filled As Boolean, StrokeWidth As Float, CornersRadius As Float)

  DrawText (Text As String, x As Float, y As Float, Font As Font, Color As Int, Align As String)

  DrawTextRotated (Text As String, x As Float, y As Float, Font As Font, Color As Int, Align As String, Degrees As Float)

  DrawView (View As Object, DestRect As Rect)

  FillGradient (x1 As Float, y1 As Float, x2 As Float, y2 As Float, Colors As List)

  Initialize (View As View)

  InitializePDF (Dir As String, FileName As String, Width As Float, Height As Float)

  NextPDFPage

  Refresh

  Release

  RemoveClip

  TargetRect As Rect [read only]

  TileBitmap (Bitmap As Bitmap, DestRect As Rect)

  View As View [read only]

Members description:

ClipPath (Path As Path)
Clips the drawing to the specified path. Call RemoveClip to remove the clip.
CreateBitmap As Bitmap
Creates a new Bitmap from the canvas layer.
DrawBitmap (Bitmap As Bitmap, DestRect As Rect)
Draws the specified bitmap in the DestRect rectangle.
DrawBitmapRotated (Bitmap As Bitmap, DestRect As Rect, Degrees As Float)
Similar to DrawBitmap. Draws a rotated bitmap.
DrawCircle (x As Float, y As Float, Radius As Float, Color As Int, Filled As Boolean, StrokeWidth As Float)
Draws a circle.
x / y - Circle center.
Radius - Circle radius.
Color - Drawing color.
Filled - Whether to fill the circle interior.
StrokeWidth - The circle border width.
DrawColor (Color As Int)
Fills the entire canvas with the given color. Note that you can use ClipPath to clip the drawings to a specific region.
DrawLine (x1 As Float, y1 As Float, x2 As Float, y2 As Float, Color As Int, StrokeWidth As Float)
Draws a line between two points.
x1, y1 - Starting point.
x2, y2 - End point.
Color - Drawing color.
StrokeWidth - Line width.
DrawPath (Path As Object, Color As Int, Filled As Boolean, StrokeWidth As Float)
Draws or fills the given path.
Path - The Path that will be filled or drawn.
Colors - Drawing color.
Filled - Whether to fill the path.
StrokeWidth - The border drawing width.
DrawPDF (Document As PDFDocument, PageNumber As Int, DestRect As Rect)
Draws a PDF page in the DestRect rectangle.
Document - PDF Document.
PageNumber - The page to draw. Note that the first page number is 1.
DestRect - Destination rectangle.
DrawRect (Rect1 As Rect, Color As Int, Filled As Boolean, StrokeWidth As Float)
Draws a rectangle.
Rect1 - Rectangle coordinates.
Color - Drawing color.
Filled - Whether to fill the rectangle interior.
StrokeWidth - The rectangle border width.
DrawRectRotated (Rect1 As Rect, Color As Int, Filled As Boolean, StrokeWidth As Float, CornersRadius As Float, Degrees As Float)
Similar to DrawRectRounded. Rotates the rectangle before it is drawn.
DrawRectRounded (Rect1 As Rect, Color As Int, Filled As Boolean, StrokeWidth As Float, CornersRadius As Float)
Similar to DrawRect. Allows you to draw a rectangle with rounded corners.
DrawText (Text As String, x As Float, y As Float, Font As Font, Color As Int, Align As String)
Draws the given text.
Text - Text to draw.
x, y - Origin point.
Font - Font to use for drawing.
Color - Drawing color.
Align - Text alignment related to the origin point. One of the following values: LEFT, CENTER or RIGHT.
DrawTextRotated (Text As String, x As Float, y As Float, Font As Font, Color As Int, Align As String, Degrees As Float)
Similar to DrawText. Draws rotated text.
DrawView (View As Object, DestRect As Rect)
Draws the given view in the DestRect rectangle.
FillGradient (x1 As Float, y1 As Float, x2 As Float, y2 As Float, Colors As List)
Paints a gradient fill along the two points.
x1, y1 - Starting point.
x2, y2 - End point.
Colors - A list (or array) with the gradient colors.
Initialize (View As View)
Initializes the canvas with the view that it will draw on.
InitializePDF (Dir As String, FileName As String, Width As Float, Height As Float)
Initializes a canvas that will create a PDF document. The default size of PDF documents is 612 x 792.
Dir / FileName - PDF file to create.
Width - Document width.
Height Document height;
NextPDFPage
Moves the canvas to the next page. Should only be used when the canvas was initialized with InitializePDF.
Refresh
Applies the changes done. You must call Refresh for the drawings to be applied.
Release
Releases the canvas resources. You can safely call this method multiple times or before the canvas was initialized.
RemoveClip
Removes the last clipping set with ClipPath.
TargetRect As Rect [read only]
Returns the canvas drawing rectangle;
TileBitmap (Bitmap As Bitmap, DestRect As Rect)
Tiles the given bitmap in the DestRect rectangle. Note that the bitmap will be drawn upside down.
View As View [read only]
Gets the attached view.

Path

Path is used together with Canvas to allow the drawing to be clipped to a polygon.

Events:

None

Members:


  Initialize (x As Float, y As Float)

  InitializeRect (Rect1 As Rect, CornerRadius As Float)

  IsInitialized As Boolean

  LineTo (x As Float, y As Float) As Path

  Tag As Object

Members description:

Initialize (x As Float, y As Float)
Initializes the Path and sets the initial position.
InitializeRect (Rect1 As Rect, CornerRadius As Float)
Initializes a path based on the given rectangle.
CornerRadius - Corners radius for rounded rectangles.
IsInitialized As Boolean
Tests whether this object was initialized.
LineTo (x As Float, y As Float) As Path
Adds a line from the current point to the specified point.
Tag As Object
Gets or sets the Tag object. This is a placeholder for any object you like to tie to this object.

Rect

An object that represents a rectangle. Mainly used with Canvas.

Events:

None

Members:


  Bottom As Float

  CenterX As Float [read only]

  CenterY As Float [read only]

  Height As Float

  Initialize (Left As Float, Top As Float, Right As Float, Bottom As Float)

  IsInitialized As Boolean

  Left As Float

  Right As Float

  ToCGRect As Object

  Top As Float

  Width As Float

Members description:

Bottom As Float
CenterX As Float [read only]
Returns the horizontal center.
CenterY As Float [read only]
Returns the vertical center.
Height As Float
Initialize (Left As Float, Top As Float, Right As Float, Bottom As Float)
Initializes a new Rect and sets its dimensions.
IsInitialized As Boolean
Left As Float
Right As Float
ToCGRect As Object
Top As Float
Width As Float

Top