> i got the correct result by scaling the roatated image by the hight in the
> x direction and by the width in the y direction(see code below), but this
> will work only for multiples of 90degrees as you can see. If this is the
> only solution(which i dearly hope is not), how can we generalize it to
> work for any angle?
> 

Welcome to the Wonderful World of matrix math.  </sarcasm>

One of the handy things about matrices is that they can be combined.  The order
in which they are combined is Important.

2D transformation matrices can be expressed in a 3x2 grid, thusly:

a b
c d
e f

A & B make up the x, c & d the y, and e & f are x & y offsets, respectively.

An "identity" matrix looks like this:
1 0
0 1
0 0
AKA 1 0 0 1 0 0

So a rotation matrix looks like:
cos sin
-sin cos
0 0
NOTE: Rotation is always around 0,0... this can lead to Weirdness if you're not
compensating for it.

And a scale matrix looks like:
x-scale 0
0 y-scale
0 0

You need to combine a scale matrix and a rotation matrix.  In Java,
AffineTransform will do the heavy lifting for you:

AffineTransform combinedTrans = AffineTransform.getScaleInstance( scaleX, 
scaleY );
combinedTrans.rotate( theta, anchorX, anchorY ); // allows you to specify
                                                 // a center of rotation.
                                                 // Very Handy
combinedTrans.translate( newX, newY );

double matrix[] = new double[6];
combinedTras.getMatrix( matrix );
contentByte.addImage( workImage, matrix[0], matrix[1],
                                 matrix[2], matrix[3],
                                 matrix[4], matrix[5]);

------------

I can never remember which order to do things in, so you might need to start
with the translation, and then rotate it, or something goofy like that.  I
always end up trying different orders till I find the "correct" one.  Quite
Annoying.

--Mark Storer
  Senior Software Engineer
  Cardiff.com

#include <disclaimer>
typedef std::disclaimer<Cardiff> DisCard;


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to