Campbell Ritchie wrote:
Arron Ferguson wrote:But then I'm faced with the entire graphics context having the transforms/translations applied to it rather than local transforms/translations.
No, you only apply the transforms to the copy object.
You need a copy object regardless; you can transform and un-transform a Graphics object, but the floating-point arithmetic is never quite precise, so your Graphics will be slightly skewed afterwards. That seems to be more of a problem with rotation and shearing than scaling or translation.
And sorry for not replying earlier. And Craig Wood's code always works well, doesn't it
Ah yes, I saw that afterwards and realized that what you just said is correct. Whether I use the AffineTransform or the methods of the Graphics2D class you can always reset it. Talking about not precise, I have yet to see a differences in quality for rotation/shear/scale. For example:
Has absolutely
no affect (or effect) on images that have been sheared, scaled, or rotated. I've tested this both on Linux (Ubuntu) as well as Vista - both using JRE 6 u10. Both computers show no change between using rendering hints either on the Graphics2D object nor on an AffineTransformOp. I've compared screen captures and zoomed in to see differences and there are none.
I came across a few bug reports on the Sun site suggesting that a couple of years back bicubic wasn't implemented and that for printing these values had undesirable artefacts but nothing particularly suggesting anything wrong with rendering hints not working. I'm less apt to file a bug report since the last few I've posted in the last few months don't get addressed - so I'll just use what works and move on.
For affine transforms in Java, I came across a fellow who made a utility class called
AffineTransformUtil and it helped me to see what was being done.
Additionally for arbitrary transforms to images, I came across
Jerry Huxtable's web page that has a library (under the Apache License) which contains a perspective filter - which was really what this whole adventure was all about: creating arbitrary (and stationary) sides to a cube based on images fed into the UI. Sometimes the search through Google takes one through some interesting paths.
And yes, Craig Wood's code works and is easy to follow.