ImagePaint

Since: BlackBerry 10.0.0

#include <bb/cascades/ImagePaint>

A representation of a image that can be used as a fill.

ImagePaint is typically used for tileable images. A tileable image is one that can be repeated as a pattern over a surface.

If set as a background of a Container the paint will fill the area occupied by the container. Depending on the specified repeat pattern the image will either be repeated in particular direction or stretched to fill the available area. The anchor point of the repeat is the top left corner of the fillable area.

This class uses RepeatPattern to specify how and if the image should be repeated over the surface. In order to construct ImagePaint objects from QML, the ImagePaintDefinition class is available.

The provided image must have a width and height that is a power of two in order to be tileable (for example, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128, 256x256, 128x64, 32x16). It also needs to have the "repeatable: true|false" property set in the asset metadata file. The asset metadata file is an .amd file with the same name as the image itself. This file can also contain nine-slicing attributes, however the tiling of nine-sliced images is not currently supported.

Here's an example of an .amd file called tiled_image.amd that has the repeatable property set to true.

#RimCascadesAssetMetaData version=1.0
source: "tiled_image.png"
repeatable: true

When referencing the image from your application, you reference the .amd file instead of the image itself. Here's an example of how to tile the background image in a container in C++:

pContainer->setBackground(ImagePaint("asset:///tiled_image.amd", RepeatPattern::XY));

Tiling images using ImageData

You can also tile images defined by the ImageData class:

#include <bb/ImageData>

int w = 0x33333333;
int b = 0000000000;
int data[8][8] =
    { { w, b, b, b, b, b, b, w },
      { b, w, b, b, b, b, w, b },
      { b, b, w, w, w, w, b, b },
      { b, b, w, b, b, w, b, b },
      { b, b, w, b, b, w, b, b },
      { b, b, w, w, w, w, b, b },
      { b, w, b, b, b, b, w, b },
      { w, b, b, b, b, b, b, w } };

Image image(bb::ImageData::fromPixels((const unsigned char*)data, bb::PixelFormat::RGBX, 8, 8, 8*4));
ImagePaint paint(image, RepeatPattern::XY);
pContainer->setBackground(paint);

Tiling images in QML

In order to tile images in QML, you must use the associated definition class ImagePaintDefinition. Here's an example of how to use ImagePaintDefinition to add a background image to a container in QML:

Container {
    id: rootContainer
    background: back.imagePaint
    attachedObjects: [
        ImagePaintDefinition {
            id: back
            repeatPattern: RepeatPattern.XY
            imageSource: "asset:///container/tiled/core16x16.amd"
        }
    ]
}   


Overview

Inheritance

bb::cascades::Paint
bb::cascades::ImagePaint

Public Functions Index

ImagePaint ()
ImagePaint (const QUrl &url, RepeatPattern::Type pattern=RepeatPattern::Fill)
ImagePaint (const Image &image, RepeatPattern::Type pattern=RepeatPattern::Fill)
ImagePaint (const ImagePaint &orig)
virtual ~ImagePaint ()
Imageimage () const
virtual booloperator!= (const Paint &other) const
virtual ImagePaint &operator= (const ImagePaint &other)
virtual booloperator== (const Paint &other) const
RepeatPattern::TyperepeatPattern () const
boolisNull () const Inherited
Paint &operator= (const Paint &other)Inherited
Paint (const Paint &orig)Inherited

Public Functions

ImagePaint ()

Default constructor which creates a null image and RepeatPattern::Fill repeat pattern.

Since:

BlackBerry 10.0.0

ImagePaint (

Creates an ImagePaint object using a QUrl pointing to a valid (power of two-sized) image.

Parameters
url

The URL to load the image from.

pattern

The repeating pattern of the image. Requires certain properties of the ImagePaint to be set.

Since:

BlackBerry 10.0.0

ImagePaint (

Creates an ImagePaint object using an Image as painting source.

Parameters
image

The image to use as source for the ImagePaint.

pattern

The repeating pattern of the image. Requires certain properties of the ImagePaint to be set

See also:

ImagePaint

Since:

BlackBerry 10.0.0

ImagePaint (

Creates an ImagePaint object using an Image as the source.

A copy constructor which creates a copy of the passed ImagePaint object.

Parameters
orig

ImagePaint object to create a copy of.

Since:

BlackBerry 10.0.0

virtual~ImagePaint ()

Destructor.

Since:

BlackBerry 10.0.0

Image image ()

Returns the image of this ImagePaint.

Return:

The Image of this paint.

Since:

BlackBerry 10.0.0

virtual bool operator!= (

A != operator for paint objects.

This is equivalent to !operator==();

Return:

true if the objects are not equal, false otherwise.

Since:

BlackBerry 10.0.0

virtualImagePaint & operator= (

Assignment operator that makes this paint a copy of the passed paint.

Parameters
other

The ImagePaint object to make a copy of.

Since:

BlackBerry 10.0.0

virtual bool operator== (

An == operator for ImagePaint objects.

The objects are equal if they stem from the same original object or if they are both null paints.

Subclasses can override these criteria in their own implementation.

See also:

SystemDefaults

Return:

true if the objects stem from the same original object, or if both paints are null, false otherwise.

Since:

BlackBerry 10.0.0

RepeatPattern::Type repeatPattern ()

Returns the repeat pattern of this ImagePaint.

Return:

The RepeatPattern of this paint.

Since:

BlackBerry 10.0.0

bool isNull ()Inherited

Checks whether this Paint object is a null paint.

Return:

true if this Paint object is a null paint, false otherwise.

Since:

BlackBerry 10.0.0

Paint & operator= (Inherited

A = operator for Paint objects.

Since:

BlackBerry 10.0.0

Paint (Inherited

Copy constructor for Paint objects.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-29



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus