Sub-Pixel Graphical Movement
I've been reading about sub-pixel accuracy but could not find a way to do this.
Q: How can I move a BufferedImage
across a Canvas
at non-integer speeds without stuttering?
I can logically understand how the process happens - slight resizing with Anti-Aliasing, but I cannot recreate this in Java. (I've had experience with Flash where such an effect is created by def开发者_如何学编程ault on most visual objects.)
Note: I've submitted a question about the subject before, but after searching for further information I still couldn't implement what I learned.
If it is not too much trouble, a simple example would be very appreciated.
Thanks in advance.
Edit: This is how I understood the effect can be achieved, though it doesn't work for me:
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.draw(new Rectangle2D.Double(x, y, width, height));
There is no visible change between double and similar int values at the x & y fields, and when I try to create very slow movement (system time based, for example) I see the rectangle doing nothing but moving a single pixel every now and then.
ButtonUITest
offers a side-by-side comparison of the effect.
On many platforms, it's possible to zoom the display to see more. On Mac OS X, ⌘-⌥-8 works, as does /Developer/Applications/Graphics Tools/Pixie.app
. On other platforms supporting Java, Zoom
is a handy tool for examining anti-aliased pixels.
Try also setting the following rendering hint (as well as anti-aliasing):
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
精彩评论