Java (최신 버전 6u23)에서 불투명 한 텍스트를 렌더링하는 동안 하위 픽셀 AA가 잘 사용되지만 반투명 텍스트는 렌더링되지 않는다는 것을 발견했습니다.자바가 서브 픽셀 AA를 사용하여 반투명 텍스트를 렌더링 할 수 있습니까?
서브 픽셀 AA :
색상 만이 0xBFFFFFFF에 0xFFFFFFFF로 변경되었습니다있는 같은 텍스트 :
당신이 볼 수 있듯이, 반투명 텍스트는 분명히 표준 AA이며 깨끗한 반투명 렌더링이 아니라 끔찍한 '90 년대'스파이더 리 '모양을 가지고 있습니다.
일반적으로 하위 픽셀 AA의 기술적 한계 또는 Java의 버그로 인한 것입니까? 아니면 자바가 반투명 텍스트를 시도하지 않았거나 뭔가 놓친 것입니까?
Object oaa=disableGeneralAA(gc);
...
gc.drawString(tl,xx,(ty+(xa*met.getHeight())));
restoreGeneralAA(gc,oaa);
...
static private volatile boolean hasRenderingHints=true;
// *****************************************************************************
// STATIC INIT & MAIN
// *****************************************************************************
// *****************************************************************************
// STATIC METHODS
// *****************************************************************************
/**
* Disable the general anti-aliasing rendering hint, returning whether the old value was RenderingHints.VALUE_ANTIALIAS_ON.
* <p>
* This method is needed for text rendering due to a bug in AWT; as of Java 6_20 when general AA is on text is not rendered using subpixel
* AA, so general AA has to be turned off before rendering text and turned back on when done. This method abstracts that work and deals
* with the possibility that the JVM does not support rendering hints, such as is the case with JME JVMs.
*/
static public Object disableGeneralAA(Graphics2D gc) {
Object old=null;
if(hasRenderingHints) {
try {
old=gc.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
}
catch(NoClassDefFoundError thr) { hasRenderingHints=false; }
catch(NoSuchFieldError thr) { hasRenderingHints=false; }
catch(NoSuchMethodError thr) { hasRenderingHints=false; }
}
return old;
}
/**
* Disable the general anti-aliasing rendering hint, returning whether the old value was RenderingHints.VALUE_ANTIALIAS_ON.
* <p>
* This method is needed for text rendering due to a bug in AWT; as of Java 6_20 when general AA is on text is not rendered using subpixel
* AA, so general AA has to be turned off before rendering text and turned back on when done. This method abstracts that work and deals
* with the possibility that the JVM does not support rendering hints, such as is the case with JME JVMs.
*/
static public void restoreGeneralAA(Graphics2D gc, Object val) {
Object old=null;
if(hasRenderingHints && val!=null) {
try { gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,val); }
catch(NoClassDefFoundError thr) { hasRenderingHints=false; }
catch(NoSuchFieldError thr) { hasRenderingHints=false; }
catch(NoSuchMethodError thr) { hasRenderingHints=false; }
}
}
안티 앨리어싱 된 텍스트를 'BufferedImage'에 렌더링 한 다음'AlphaComposite '를 사용하여 이미지를 화면에 반투명하게 그려 보았습니까? (불행히도 더 느려질 것입니다.) – finnw
@finnw : 모든 페인팅은 오프 스크린 BufferedImage로 이루어지며, 그 이미지는 간단한'gc.drawImage'를 사용하여 각 페인트 (그래픽 agc)의 기본 스크린 그래픽 콘텍스트로 복사됩니다. . 나는 오프 스크린 버퍼의 이미지가 최종 이미지가 될 것으로 기대한다. 나는 반투명 한 페인팅을 많이하고 유일한 문제는 텍스트 색이 반투명 할 때 텍스트 렌더링이 표준 AA로 보인다는 것입니다. –
잠시 동안이 문제가 발생했습니다. http://forums.java.net/node/676951 – z5h