Class: Toybox.Graphics.BufferedBitmap

Overview

This class represents an off-screen bitmap. It provides methods to modify the bitmap palette, and get a drawable context.

See Also:

Example:

Sets up an off-screen buffer using resources.

using Toybox.Graphics;

var screenShape;
var offscreenBuffer;
var dateBuffer;

    if (Toybox.Graphics has :BufferedBitmap) {              // check to see if device has BufferedBitmap enabled
        offscreenBuffer = new Graphics.BufferedBitmap(
                {:width=>dc.getWidth(),
                 :height=>dc.getHeight(),
                 :palette=>[Graphic.COLOR_DK_GRAY,
                            Graphics.COLOR_LT_GRAY,
                            Graphics.COLOR_BLACK,
                            Graphics.COLOR_WHITE]} );       // create an off-screen buffer with a palette of four colors

        stringBuffer = new Graphics.BufferedBitmap(         // Buffer will have full color support as no palette is defined
                {:width=>dc.getWidth(),
                 :height=>Graphics.getFontHeight(Graphics.FONT_MEDIUM)} );
    } else {
        offscreenBuffer = null;                             // handle devices without BufferedBitmap
        stringBuffer = null;
    }

Since:

API Level 2.3.0

Instance Method Summary collapse

Instance Method Details

getDc() as Graphics.Dc

Get the Dc to draw on the buffered bitmap.

Returns:

Since:

API Level 2.3.0

getHeight() as Lang.Number

Get the height of a bitmap.

Returns:

Since:

API Level 4.0.0

getPalette() as Lang.Array<Graphics.ColorType>

null if this surface uses the system palette

Returns:

  • Lang.Array

    The current palette for this bitmap.

Since:

API Level 2.3.0

getWidth() as Lang.Number

Get the width of a bitmap.

Returns:

Since:

API Level 4.0.0

initialize(options as { :width as Lang.Number, :height as Lang.Number, :palette as Lang.Array<Graphics.ColorType>, :colorDepth as Lang.Number, :bitmapResource as WatchUi.BitmapResource, :alphaBlending as Graphics.AlphaBlending })

Constructor

Parameters:

  • options(Lang.Dictionary)

    Dictionary of options. Must contain width and height, with optional palette, or a BitmapResource. This resource is not allowed to have an alpha channel.

    • :width(Lang.Number)

      The width of the surface in pixels

    • :height(Lang.Number)

      The height of the surface in pixels

    • :palette(Lang.Array)

      The colors used in this surface. Using less will reduce the bitmap size. The bitmap will use the system default if not provided. The maximum palette size allowed is 256 colors. If a palette is provided, the number of colors must also be <= to the number of system colors.

    • :colorDepth(Lang.Number)

      Color depth in terms of bits/pixel, when missing, default to system value.

    • :bitmapResource(WatchUi.BitmapResource)

      A BitmapResource to initialize

    • :alphaBlending(Lang.Number)

      A AlphaBlending enum to specify the level of alpha blending support for this buffered bitmap object

Since:

API Level 2.3.0

Throws:

isCached() as Lang.Boolean

Check if the memory for the bitmap is still loaded in the memory User can invoke this method to check if the underlying resource is still available in the memory since last used if true, the resource such as BufferedBitmap has been cached and can be used directly without re-drawing.

Returns:

  • Lang.Boolean

    true if the object's memory has not been recycled since last usage.

Since:

API Level 4.0.0

setPalette(palette as Lang.Array<Graphics.ColorType>) as Void

Parameters:

  • palette(Lang.Array)

    A palette for this bitmap. The number of colors must match the current palette. Each color in the image will be replaced with the colors specified in the new palette.

Since:

API Level 2.3.0

Throws:


Generated Nov 29, 2021 1:34:35 PM