com.flagstone.transform.fillstyle
Class BitmapFill

java.lang.Object
  extended by com.flagstone.transform.fillstyle.BitmapFill
All Implemented Interfaces:
Copyable<FillStyle>, SWFEncodeable, FillStyle

public final class BitmapFill
extends Object
implements FillStyle

BitmapFill is used to display an image inside a shape. An image cannot be displayed directly, it must be displayed inside of a shape using this style. The style controls how the image is displayed inside the shape. Images may be clipped if they are too large to fit or tiled across the available area if they are too small. A coordinate transform can also be used to change its size, location relative to the origin of the shape, orientation, etc., when it is displayed. Four types of bitmap fill are supported:

  1. Clipped - If the image is larger than the shape then it will be clipped. Conversely if the area to be filled is larger than the image the colour at the edge of the image is used to fill the remainder of the shape.
  2. Tiled - if the area to be filled is larger than the image then the image is tiled to fill the area, otherwise as with the Clipped style the colour at the edge of the image will be use to fill the space available.
  3. Unsmoothed Clipped - Same as Clipped but if the image is smaller than the shape the colour used to fill the space available is not smoothed. This style was added to increase performance with few visible artifacts.
  4. Unsmoothed Tiled - Same as Tiled but no smoothing is applied if the colour at the edge of the image is used to fill the space available. Again this was introduced to increase performance.

The most common use of the coordinate transform is to scale an image so it displayed at the correct resolution. When an image is loaded its width and height default to twips rather than pixels. An image 300 x 200 pixels will be displayed as 300 x 200 twips (15 x 10 pixels). Scaling the image by 20 (20 twips = 1 pixel) using the CoordTransform object will restore it to its original size.

The coordinate transform is also used to control the image registration. An image is drawn with the top left corner placed at the origin (0, 0) of the shape being filled. The transform can be used to apply different translations to the image so its position can be adjusted relative to the origin of the enclosing shape.


Constructor Summary
BitmapFill(BitmapFill object)
          Creates and initialises a BitmapFill fill style using the values copied from another BitmapFill object.
BitmapFill(boolean tiled, boolean smoothed, int uid, CoordTransform position)
          Creates a BitmapFill object, setting the fill type, the unique identifier for the image and the coordinate transform used to set the scale and registration of the image.
BitmapFill(int fillType, SWFDecoder coder)
          Creates and initialises a BitmapFill fill style using values encoded in the Flash binary format.
 
Method Summary
 BitmapFill copy()
          Creates a complete copy of this object.
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 int getIdentifier()
          Get the unique identifier of the object containing the image to be displayed.
 CoordTransform getTransform()
          Get the coordinate transform that will be applied to the image when it is displayed.
 boolean isSmoothed()
          Is the image smoothed to increase quality.
 boolean isTiled()
          Is the image tiled across the area defined in the shape.
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 void setIdentifier(int uid)
          Sets the unique identifier of the object containing the image to be displayed.
 void setSmoothed(boolean smoothed)
          Sets whether the image smoothed when it is displayed.
 void setTiled(boolean tiled)
          Sets whether the image tiled across the area defined in the shape.
 void setTransform(CoordTransform matrix)
          Sets the coordinate transform applied to the image to display it inside the shape.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitmapFill

public BitmapFill(int fillType,
                  SWFDecoder coder)
           throws IOException
Creates and initialises a BitmapFill fill style using values encoded in the Flash binary format.

Parameters:
fillType - the value used to identify the fill style when it is encoded.
coder - an SWFDecoder object that contains the encoded Flash data.
Throws:
IOException - if an error occurs while decoding the data.

BitmapFill

public BitmapFill(boolean tiled,
                  boolean smoothed,
                  int uid,
                  CoordTransform position)
Creates a BitmapFill object, setting the fill type, the unique identifier for the image and the coordinate transform used to set the scale and registration of the image.

Parameters:
tiled - whether the image will be repeated if it smaller than the area to be filled.
smoothed - whether the image will be smoothed to improve display quality.
uid - the unique identifier of the object containing the image to be displayed. Must be in the range 1..65535.
position - a CoordTransform object that typically changes the size and location and position of the image inside the parent shape.

BitmapFill

public BitmapFill(BitmapFill object)
Creates and initialises a BitmapFill fill style using the values copied from another BitmapFill object.

Parameters:
object - a BitmapFill fill style from which the values will be copied.
Method Detail

isTiled

public boolean isTiled()
Is the image tiled across the area defined in the shape.

Returns:
true if the image is tiled, false otherwise.

setTiled

public void setTiled(boolean tiled)
Sets whether the image tiled across the area defined in the shape.

Parameters:
tiled - true if the image should be tiled, false if it is clipped.

isSmoothed

public boolean isSmoothed()
Is the image smoothed to increase quality.

Returns:
true if the image is smoothed, false otherwise.

setSmoothed

public void setSmoothed(boolean smoothed)
Sets whether the image smoothed when it is displayed.

Parameters:
smoothed - true if the image should be smoothed, false if no smoothing will be applied.

getIdentifier

public int getIdentifier()
Get the unique identifier of the object containing the image to be displayed.

Returns:
the unique identifier for the image to be displayed.

setIdentifier

public void setIdentifier(int uid)
Sets the unique identifier of the object containing the image to be displayed.

Parameters:
uid - the unique identifier of the object containing the image to be displayed which must be in the range 1..65535.

getTransform

public CoordTransform getTransform()
Get the coordinate transform that will be applied to the image when it is displayed.

Returns:
the coordinate transform applied to the image.

setTransform

public void setTransform(CoordTransform matrix)
Sets the coordinate transform applied to the image to display it inside the shape. Typically the transform will scale the image by a factor of 20 so that the image is displayed at the correct screen resolution.

Parameters:
matrix - a CoordTransform object that changes the appearance and location of the image inside the shape. Must not be null.

copy

public BitmapFill copy()
Creates a complete copy of this object.

Specified by:
copy in interface Copyable<FillStyle>
Returns:
a deep-copy of this object. New instances of mutable objects are copied and immutable instances are shared.

toString

public String toString()
Overrides:
toString in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.