For example to draw a rectangle on a canvas I use Rectangle2D.Double, but I need to draw images with double type parameters. That's possible? since it only accepts parameters of type int..
Asked
Active
Viewed 696 times
2
-
2Since the `drawImage` API only allows `int` parameters, no. `AffineTransform` allows you to translate the origin point using double's, so, technically, you could translate the context with the specified values and then draw the image at `0x0` - just don't forget to reset the transformation – MadProgrammer Jun 12 '18 at 02:42
-
Round the double value to the nearest integer then cast it to an int like so `(int) myDouble`. – sorifiend Jun 12 '18 at 03:07
-
Use this answer: https://stackoverflow.com/questions/8676909/drawing-an-image-using-sub-pixel-level-accuracy-using-graphics2d – Dmitry Kamenetsky Nov 10 '22 at 11:46
1 Answers
1
Use an AffineTransform
translate instance. They can work with double values. The resulting image drawing will then be 'dithered' along the edges to show what appears to be 'sub pixel accuracy' rendering.

Andrew Thompson
- 168,117
- 40
- 217
- 433