Matrices in Java and Flash (Flex)

Ran into an interesting detail concerning differences between Flex and Java, having to do with their matrix representations.  If you are unfamiliar with Matrices, as I am, you can review Matrices and Transformations in Flash at  The detail is this:  Java and Flash have their second and third at the opposite to each other.  So, for example, in this matrix:

Matrix Picture

In Flash, you would say:

matrix = new Matrix(a, b, c, d, tx, ty);

and in Java, it look like:

matrix = new Matrix(a, c, b, d, tx, ty);

(Well, their matrix is spelled a little differently.  See the javadoc page at :

[  m00  m01  m02  ] 

[  m10  m11  m12  ]

 This was one thorny detail on top of the rest of the great fun of the iText library.  The other interesting piece is that the y coordinates are reversed.  The PDF was designed for print media, so the y starts at the bottom of the page, with increasing values as it goes up.  In Flash, it is the opposite.  The y origin is at the top of the screen, increasing in value as you go downward.  This is all in general, and default.  It is possible to apply a transformation to the PDF to reverse the Y values, and likewise with the Flash.

With the PDF, you can apply the following transofmation:

matrix(1.o, 0.0, 0.0, -1.0, 0.0,  h*)

using concatCTM most likely.  The d value reverses the direction of the y axis, and the h* is a special value which is on the overall height of the page.   Because once you reverse the y value, it is still originated at the bottom left.  But when it increases it goes off the page into oblivion.  The h* value moves the origin to the upper left hand corner of the page.


One Response to Matrices in Java and Flash (Flex)

  1. zieed says:

    i want to create a pdf document with itext , i have a probleme to get the same result in java as in flex. i use the graphics2d in java to draw a shape that use a matrix transformation get by flex but the result is not the same . i want to know if there is other element that affect the result like the dpi or the number of shape .
    thanks for help.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: