Made to Order Software Corporation Logo

Appendix A — The geometry in SWF — Images

When appropriate, images can also be included in SWF files. All the images can be full color and also have an alpha channel.

In order to draw an image on the screen, it is necessary to use a fill style and a shape. Thus, you need at least three tags: DefineBitsLossless or DefineBitsJPEG, a DefineShape and a PlaceObject in order to draw an image on the screen. The fill style of the shape needs to include a matrix with a scale of 20x20 in order to draw the image at the original sizes. Also the rectangle used to draw around the image will use 20 TWIPS per pixels of the image. Like with other shapes, if it is necessary to rotate the image by the center, then the shape will have to be defined with a MOVE to (width / -2.0, height / -2.0) and the image rectangle drawn around the center. With edges, this means a set of positions such as:

  • Move to (width/-2, height/-2)
  • +(width, 0)
  • +(0, height)
  • +(-width, 0)
  • +(0, -height)

If you want to draw the image only once, you should make sure that the fill is of type clipped. A tilled image could be drawn multiple times.

There is an example of a 640x480 image:

Tag: DefineBitsLossless
Object ID: 1
Format: 5 (32 bits ARGB)
Bitmap sizes: 640x480

Tag: DefineShape
Object ID: 2
Rectangle: (0, 0) - (12800, 9600)
Fill Style #1:
  Clipped Bitmap, ID: 1
  Matrix:
    Scale 20x20
    Translate: (-6400, -4800)
Edges:
  Move (-6400, -4800)
  Use fill #1
  Delta (12800, 0)
  Delta (0, 9600)
  Delta (-12800, 0)
  Delta (0, -9600)

Tag: PlaceObject
Place Object: #2
Depth: 1
Matrix:
  Translate: (6400, 4800)

Note that it is possible that one pixel will be missing using such values. It isn't rare to add 20 to the Edges deltas in order to include the missing pixel (this is mainly due to the computation of the anti-aliasing effect).