2

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?

Acidic
  • 6,154
  • 12
  • 46
  • 80

1 Answers1

4

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).

prunge
  • 22,460
  • 3
  • 73
  • 80