Sub-pixel Image rendering

霸气de小男生 提交于 2021-02-19 06:39:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!