亚像素图像渲染 [英] Sub-pixel Image rendering
问题描述
我知道子像素的形状,例如 Rectangle2D.Double
, Ellipse2D.Double
和 Line2D.Double
-但我做不到找不到有关以亚像素精度绘制 Image
/ BufferedImage
的信息.
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.
也许看起来像这样- Image2D.Double
?
有什么办法可以做到这一点?
Is there any way I can achieve this?
推荐答案
Images may be drawn with an AffineTransform, which can specify scaling and translation with floating point values.
(请参见例如,要绘制缩放到一半大小且位置(10.5,10.5)的图像,请使用:
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);
您应确保 RenderingHints 已在Graphics2D对象上设置(对于初学者,将 KEY_ANTIALIASING
设置为 VALUE_ANTIALIAS_ON
).
You should ensure that appropriate RenderingHints have been set on the Graphics2D object (set KEY_ANTIALIASING
to VALUE_ANTIALIAS_ON
for starters).
这篇关于亚像素图像渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!