问题
I am aware of sub-pixel shapes, such as Rectangle2D.Double
, Ellipse2D.Double
and Line2D.Double
- but I couldn't find information about drawing an Image
/ BufferedImage
with sub-pixel accuracy.
Perhaps something that would look like this - Image2D.Double
?
Is there any way I can achieve this?
回答1:
Images may be drawn with an AffineTransform, which can specify scaling and translation with floating point values.
(See drawImage(Image, AffineTransform, ImageObserver) method)
For example, to draw an image scaled to half size and at position (10.5, 10.5), use:
Graphics2D g = ...
BufferedImage myImage = ...
AffineTransform t = new AffineTransform();
t.translate(10.5, 10.5);
t.scale(0.5, 0.5);
g.drawImage(myImage, t, null);
You should ensure that appropriate RenderingHints have been set on the Graphics2D object (set KEY_ANTIALIASING
to VALUE_ANTIALIAS_ON
for starters).
来源:https://stackoverflow.com/questions/8335340/sub-pixel-image-rendering