An object that holds a bitmap image. The bitmap can be loaded from a file or other input stream, or can be set from a different bitmap. Loading large bitmaps can easily lead to out of memory exceptions. This is true even if the file is compressed and not large as the bitmap is stored uncompressed in memory. For large images you can call InitializeSample and load a subsample of the image. The whole image will be loaded with a lower resolution.
Returns the color of the pixel at the specified position.
HeightAsInt [read only]
Returns the bitmap height.
Initialize (DirAsString, FileNameAsString)
Initializes the bitmap from the given file. Note that the image will be downsampled if there is not enough memory available. Example: DimBitmap1AsBitmap Bitmap1.Initialize(File.DirAssets, "X.jpg")
Initialize2 (InputStreamAsjava.io.InputStream)
Initializes the bitmap from the given stream.
Initialize3 (BitmapAsandroid.graphics.Bitmap)
Initializes the bitmap with a copy of the original image (copying is done if necessary).
InitializeMutable (WidthAsInt, HeightAsInt)
Creates a new mutable bitmap with the specified dimensions. You can use a Canvas object to draw on this bitmap.
Initializes the bitmap from the given file. The decoder will subsample the bitmap if MaxWidth or MaxHeight are smaller than the bitmap dimensions. This can save a lot of memory when loading large images. Note that the actual dimensions may be larger than the specified values.
Writes the bitmap to the output stream. Quality - Value between 0 (smaller size, lower quality) to 100 (larger size, higher quality), which is a hint for the compressor for the required quality. Format - JPEG or PNG.
A drawable that draws a bitmap. The bitmap is set during initialization. You can change the way the bitmap appears by changing the Gravity property. Example: DimbdAsBitmapDrawable bd.Initialize(LoadBitmap(File.DirAssets, "SomeImage.png"))
bd.Gravity = Gravity.FILL Activity.Background = bd This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
A Canvas is an object that draws on other views or (mutable) bitmaps. When the canvas is initialized and set to draw on a view, a new mutable bitmap is created for that view background, the current view's background is copied to the new bitmap and the canvas is set to draw on the new bitmap. The canvas drawings are not immediately updated on the screen. You should call the target view Invalidate method to make it refresh the view. This is useful as it allows you to make several drawings and only then refresh the display. The canvas can be temporary limited to a specific region (and thus only affect this region). This is done by calling ClipPath. Removing the clipping is done by calling RemoveClip. You can get the bitmap that the canvas draws on with the Bitmap property. This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
Gets or sets whether antialiasing will be applied.
BitmapAsBitmap [read only]
Returns the bitmap that the canvas draws to. Example: Saves the drawing to a file DimOutAsOutputStream Out = File.OpenOutput(File.DirRootExternal, "Test.png", False)
Canvas1.Bitmap.WriteToStream(out, 100, "PNG")
Out.Close
ClipPath (Path1Asandroid.graphics.Path)
Clips the drawing area to the given path.
Example: Fills a diamond shape with gradient color. DimGradient1AsGradientDrawable DimClrs(2) AsInt Clrs(0) = Colors.Black Clrs(1) = Colors.White Gradient1.Initialize("TOP_BOTTOM", Clrs)
DimPath1AsPath Path1.Initialize(50%x, 100%y)
Path1.LineTo(100%x, 50%y)
Path1.LineTo(50%x, 0%y)
Path1.LineTo(0%x, 50%y)
Path1.LineTo(50%x, 100%y)
Canvas1.ClipPath(Path1) 'clip the drawing area to the path. DestRect.Left = 0%y DestRect.Top = 0%y DestRect.Right = 100%x DestRect.Bottom = 100%y Canvas1.DrawDrawable(Gradient1, DestRect) 'fill the drawing area with the gradient. Activity.Invalidate
Draws a bitmap. SrcRect - The subset of the bitmap that will be drawn. If Null then the complete bitmap will be drawn. DestRect - The rectangle that the bitmap will be drawn to.
Example: DimBitmap1AsBitmap Bitmap1.Initialize(File.DirAssets, "X.jpg")
DimDestRectAsRect DestRect.Initialize(10dip, 10dip, 10dip + 100dip, 10dip + 100dip)
Canvas1.DrawBitmap(Bitmap1, Null, DestRect) 'draws the bitmap to the destination rectangle.
DimSrcRectAsRect SrcRect.Initialize(0, 0, Bitmap1.Width / 2, Bitmap1.Height) 'the left half of the bitmap. DestRect.Top = 200dip DestRect.Bottom = 200dip + 100dip Canvas1.DrawBitmap(Bitmap1, SrcRect, DestRect) 'draws half of the bitmap. Activity.Invalidate
Flips the bitmap and draws it. SrcRect - The subset of the bitmap that will be drawn. If Null then the complete bitmap will be drawn. DestRect - The rectangle that the bitmap will be drawn to. Vertically - Whether to flip the bitmap vertically. Horizontally - Whether to flip the bitmap horizontally. Example: Canvas1.DrawBitmapFlipped(Bitmap1, Null, DestRect, False, True)
Rotates the bitmap and draws it. SrcRect - The subset of the bitmap that will be drawn. If Null then the complete bitmap will be drawn. DestRect - The rectangle that the bitmap will be drawn to. Degrees - Number of degrees to rotate the bitmap (clockwise). Example: Canvas1.DrawBitmapRotated(Bitmap1, Null, DestRect, 70)
Fills the entire canvas with the given color. Example: Canvas1.DrawColor(Colors.ARGB(100, 255, 0, 0)) 'fills with semi-transparent red color. Activity.Invalidate
Draws a line from (x1, y1) to (x2, y2). StrokeWidth determines the width of the line. Example: Canvas1.DrawLine(100dip, 100dip, 200dip, 200dip, Colors.Red, 10dip)
Activity.Invalidate
Rotates the oval and draws it. Filled - Whether the rectangle will be filled. StrokeWidth - The stroke width. Relevant when Filled = False. Degrees - Number of degrees to rotate the oval (clockwise).
Rotates the rectangle and draws it. Filled - Whether the rectangle will be filled. StrokeWidth - The stroke width. Relevant when Filled = False. Degrees - Number of degrees to rotate the rectangle (clockwise).
Draws the text. Text - The text to be drawn. x, y - The origin point. Typeface1 - Typeface (font) to use. TextSize - This value will be automatically scaled so do not scale it yourself. Color - Text color. Align - The alignment related to the origin. One of the following values: "LEFT", "CENTER", "RIGHT". Example: Canvas1.DrawText("This is a nice sentence.", 200dip, 200dip, Typeface.DEFAULT_BOLD, 30, Colors.Blue, "LEFT")
Rotates the text and draws it. Text - The text to be drawn. x, y - The origin point. Typeface1 - Typeface (font) to use. TextSize - This value will be automatically scaled so do not scale it yourself. Color - Text color. Align - The alignment related to the origin. One of the following values: "LEFT", "CENTER", "RIGHT". Degrees - Number of degrees to rotate (clockwise). Example: Canvas1.DrawTextRotated("This is a nice sentence.", 200dip, 200dip, _
Typeface.DEFAULT_BOLD, 30, Colors.Blue, "CENTER", -45)
Initialize (TargetAsandroid.view.View)
Initializes the canvas for drawing on a view. The view background will be drawn on the canvas during initialization. Note that you should not change the view's background after calling this method.
Example: DimCanvas1AsCanvas Canvas1.Initialize(Activity) 'this canvas will draw on the activity background
Initialize2 (BitmapAsandroid.graphics.Bitmap)
Initializes the canvas for drawing on this bitmap. The bitmap must be mutable. Bitmaps created from files or input streams are NOT mutable.
Returns the height of the given text. Example of drawing a blue text with white rectangle as the background: DimRect1AsRect Dimwidth, heightAsFloat DimtAsString t = "Text to write" width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)
height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14)
Rect1.Initialize(100dip, 100dip, 100dip + width, 100dip + height)
Canvas1.DrawRect(Rect1, Colors.White, True, 0)
Canvas1.DrawText(t, Rect1.Left, Rect1.Bottom, Typeface.DEFAULT, 14, Colors.Blue, "LEFT")
Returns the width of the given text. Example of drawing a blue text with white rectangle as the background: DimRect1AsRect Dimwidth, heightAsFloat DimtAsString t = "Text to write" width = Canvas1.MeasureStringWidth(t, Typeface.DEFAULT, 14)
height = Canvas1.MeasureStringHeight(t, Typeface.DEFAULT, 14)
Rect1.Initialize(100dip, 100dip, 100dip + width, 100dip + height)
Canvas1.DrawRect(Rect1, Colors.White, True, 0)
Canvas1.DrawText(t, Rect1.Left, Rect1.Bottom, Typeface.DEFAULT, 14, Colors.Blue, "LEFT")
A drawable that has a solid color and can have round corners. Example: DimcdAsColorDrawable cd.Initialize(Colors.Green, 5dip)
Button1.Background = cd This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
Initializes this object. Orientation - The gradient orientation. Can be one of the following value: "TOP_BOTTOM" "TR_BL" (Top-Right to Bottom-Left) "RIGHT_LEFT" "BR_TL" (Bottom-Right to Top-Left) "BOTTOM_TOP" "BL_TR" (Bottom-Left to Top-Right) "LEFT_RIGHT" "TL_BR" (Top-Left to Bottom-Right)
A path is a collection of points that represent a connected path. The first point is set when it is initialized, and then other points are added with LineTo.
A drawable that holds other drawables and chooses the current one based on the view's state. See the StateListDrawable example. This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
Adds the drawable that will be used if no other state matched the current state. This should always be the last state (states added after this one will never be used).
Adds a state and drawable pair. The state is made from a combination of states. You should not reuse the array specified as it is used internally by StateListDrawable. Note that the order of states is very important. The first state that matches will be used.