第一图是旋转了几次后的有锯齿,后面3副图是没有旋转的。代码如下:publicclasscoreRotateextendsJLabel{privatedoubletheta=0;protectedvoidpaintComponent(Graphicsg){System.out.p...
第一图是旋转了几次后的有锯齿,后面3副图是没有旋转的。代码如下:public class coreRotate extends JLabel { private double theta = 0; protected void paintComponent(Graphics g) { System.out.println("--------------11--------"); int w = this.getWidth(), h = this.getHeight(); double theta = Math.toRadians(this.theta); Graphics2D g2d = (Graphics2D) g; // 消除锯齿 RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2d.setRenderingHints(renderingHints); g2d.rotate(theta, w / 2, h / 2); super.paintComponent(g); } public void driveCore(double angle) { System.out.println("--------------33--------"); theta = angle; Graphics g=this.getGraphics(); this.paintComponent(g); }}
第一幅图旋转后不但导致锯齿,四边本来圆变成了看上去像方的,要怎么改呢?
展开