Java 6에서 내 스윙 GUI 응용 프로그램을 실행할 때 모든 글꼴에 대해 구성된 하위 픽셀 앤티 앨리어스 설정이 자동으로 사용됩니다. 결과는 표준 AA 옵션보다 훨씬 향상되었습니다.스윙과 같이 화면 텍스트에 페인팅 텍스트의 시스템 앤티 앨리어싱 설정을 상속하려면 어떻게해야합니까?
하지만 이미지를 칠할 때 그래픽 컨텍스트를 초기화하여 시스템의 AA 구성을 사용할 방법이 없습니다. 자바의 다른 AA 힌트를 가지고 놀러 다니는 것은 모든 사용자에게 서브 픽셀 방법이 적용되지 않기 때문에 잃어버린 원인입니다.
하나를 선택하고 명시 적으로 힌트를 설정하지 않고 주어진 그래픽 컨텍스트에 대해 시스템 AA 설정을 상속하는 방법이 있습니까? 현재 표준 AA가 제공하는 끔찍한 결과를 피하기 위해 GASP AA를 사용해야합니다. 나는 텍스트 AA에 대해 아무 것도 설정하지 않고 AA 힌트를 전혀 설정하지 않으려 고 노력했다.
업데이트 내가이 아래로 고정 있다고 생각 2010-01-05
; 서브 픽셀의 AA 힌트는, AWT 그래픽스 문맥에 직접 페인트 할 경우에만 존중되는 것처럼 보입니다. 이중 버퍼 이미지에 페인트 할 때 표준 AA 만 수행합니다. 하지만 더블 버퍼 이미지를 우회하면 서브 픽셀 AA가 완료됩니다.
그렇지 않으면 The_Fire의 대답은 Swing을 사용할 수있는 JVM (J2ME JVM이 아님)에서 작동합니다. AWT 컴퍼넌트를 사용하면, 새로운 JLabel() 대신에 새로운 Label()를 사용해 The_Fire의 대답이 기능하지 않는 것에주의 해주세요. 아마도, Component가 디스플레이에 구현 될 때까지는 FontRenderContext를 추출 할 수 없기 때문입니다. 내 목표 이미지의 그래픽 컨텍스트를 얻을
내 현재 코드는 현재 다음과 같습니다
try {
if((dbImage=dctRoot.createImage(wid,hgt,1))!=null) { // if createImage returns null or throws an exception the component is not yet displayable
dbGraphics=(Graphics2D)dbImage.getGraphics();
if(dctRoot.properties.getBoolean("Antialias",true)) {
try {
// set AA on overall
dbGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING ,RenderingHints.VALUE_ANTIALIAS_ON);
// set text AA to platform/impl default
dbGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
// try to override platform/impl AA with font-specified AA (Java 6+)
try { dbGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.class.getField("VALUE_TEXT_ANTIALIAS_GASP").get(null)); } catch(Throwable thr) {;} // yes, ignore exception
}
catch(Throwable thr) {
dctRoot.log.println("Antialiasing not supported on this JVM ("+thr+").");
dctRoot.setProperty("Antialias","False"); // turn off AA for subsequent painting
}
}
}
}
catch(Throwable thr) {
dbImage=null;
dbGraphics=null;
}
이미지를 만들 수있는 코드가되는 배경을 형성하는 기본 AWT 구성 요소를 사용합니다 I 다른 모든 AWT 구성 요소와 잘 작동하도록 setFocusCycleRoot를 수행 할 수 있어야하므로 필자의 모든 페인팅을 수행합니다. 구성 요소는 Panel입니다. 이미지를 만드는 코드는 다음과 같습니다 스윙을 사용하여
public DctImage createImage(int wid, int hgt, float accpty) {
GraphicsConfiguration cfg=awtComponent.getGraphicsConfiguration();
Image img=null;
if(transparentImages) {
//y { img=new BufferedImage(wid,hgt,BufferedImage.TYPE_INT_ARGB); } // NB: J2ME CDC/PP 1.1 does not have the BufferedImage constructors (one day I may discover a way to create a BufferedImage via another API!!)
try { img=cfg.createCompatibleImage(wid,hgt,Transparency.TRANSLUCENT); }// NB: J2ME CDC/PP 1.1 does not have this API, but prefer to use GraphicsConfiguration over new BufferImage(...)
catch(NoClassDefFoundError thr) { transparentImages=false; createImage(wid,hgt,accpty); } // try again with transparency disabled
catch(NoSuchMethodError thr) { transparentImages=false; createImage(wid,hgt,accpty); } // try again with transparency disabled
catch(NoSuchFieldError thr) { transparentImages=false; createImage(wid,hgt,accpty); } // try again with transparency disabled
}
else {
img=cfg.createCompatibleImage(wid,hgt);
}
if(accpty>0 && SET_ACCELERATION_PRIORITY!=null) {
try { SET_ACCELERATION_PRIORITY.invoke(img,new Object[]{new Float(accpty)}); } catch(Throwable thr) {;}
}
return (img==null ? null : new DctImage(img));
}
온 스크린 또는 오프 스크린과 관련이 없으므로 (답변이 아닌 주석이므로) 문자열의 특정 외국 문자가 스윙을 일으켜 TextLayout 글꼴 렌더링으로 다시 전환되는 것을 알고 있습니다 (안티 앨리어싱 된), 맞죠? – whybird