Java开发网 |
注册 |
登录 |
帮助 |
搜索 |
排行榜 |
发帖统计
|
您没有登录 |
» Java开发网 » Java SE 综合讨论区
打印话题 寄给朋友 订阅主题 |
作者 | Re:求助关于Java的抗锯齿实现 [Re:widewindow] |
widewindow
发贴: 9 积分: 0 |
于 2008-06-11 10:50
I use following simple but completely runnable java program to test anti-aliasing: /* * Copyright 2000 David Flanagan. All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import javax.swing.JFrame; import javax.swing.JPanel; /** A demonstration of anti-aliasing */ class AntiAlias extends JPanel{ static final int WIDTH = 650, HEIGHT = 350; // Size of our example public String getName() { return "AntiAliasing"; } public int getWidth() { return WIDTH; } public int getHeight() { return HEIGHT; } /** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; BufferedImage image = // Create an off-screen image new BufferedImage(65, 35, BufferedImage.TYPE_INT_ARG; Graphics2D ig = image.createGraphics(); // Get its Graphics for drawing // Set the background to a gradient fill. The varying color of // the background helps to demonstrate the anti-aliasing effect ig.setPaint(new GradientPaint(0, 0, Color.black, 65, 35, Color.white)); ig.fillRect(0, 0, 65, 35); // Set drawing attributes for the foreground. // Most importantly, turn on anti-aliasing. ig.setStroke(new BasicStroke(2.0f)); // 2-pixel lines ig.setFont(new Font("Serif", Font.BOLD, 18)); // 18-point font ig.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); /*ig.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); ig.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);*/ ig.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); // Now draw pure blue text and a pure red oval ig.setColor(Color.blue); //ig.drawString("Java", 9, 22); //ig.setColor(Color.red); //ig.drawOval(1, 1, 32, 32); ig.drawLine(13, 0, 19, 0); ig.drawLine(10, 1, 22, 1); ig.drawLine(8, 2, 24, 2); ig.drawLine(7, 3, 25, 3); ig.drawLine(6, 4, 26, 4); ig.drawLine(5, 5, 27, 5); ig.drawLine(4, 6, 28, 6); ig.drawLine(3, 7, 29, 7); ig.drawLine(3, 8, 29, 8); ig.drawLine(2, 9, 30, 9); ig.drawLine(2, 10, 30, 10); ig.drawLine(2, 11, 30, 11); ig.drawLine(1, 12, 31, 12); ig.drawLine(1, 13, 31, 13); ig.drawLine(1, 14, 31, 14); ig.drawLine(1, 15, 31, 15); ig.drawLine(1, 16, 31, 16); ig.drawLine(1, 17, 31, 17); ig.drawLine(1, 18, 31, 18); ig.drawLine(2, 19, 30, 19); ig.drawLine(2, 20, 30, 20); ig.drawLine(2, 21, 30, 21); ig.drawLine(3, 22, 29, 22); ig.drawLine(3, 23, 29, 23); ig.drawLine(4, 24, 28, 24); ig.drawLine(5, 25, 27, 25); ig.drawLine(6, 26, 26, 26); ig.drawLine(7, 27, 25, 27); ig.drawLine(8, 28, 24, 28); ig.drawLine(10, 29, 22, 29); ig.drawLine(13, 30, 19, 30); // Finally, scale the image by a factor of 10 and display it // in the window. This will allow us to see the anti-aliased pixels g.drawImage(image, AffineTransform.getScaleInstance(10, 10), this); // Draw the image one more time at its original size, for comparison g.drawImage(image, 0, 0, this); } public static void main(String[] a) { JFrame f = new JFrame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setContentPane(new AntiAlias()); f.setSize(400,400); f.setVisible(true); } } My question is, is there any debugging tool that can trace into the system code after f.setVisible(true); ? From there, I think the anti-aliasing job is down by the java system modules. 我有一点感想和初学者们同享(原创) |
话题树型展开 |
人气 | 标题 | 作者 | 字数 | 发贴时间 |
19582 | 求助关于Java的抗锯齿实现 | widewindow | 592 | 2008-06-05 16:03 |
16131 | Re:求助关于Java的抗锯齿实现 | JiafanZhou | 556 | 2008-06-05 17:47 |
15375 | Re:求助关于Java的抗锯齿实现 | JiafanZhou | 151 | 2008-06-27 16:22 |
16337 | Re:求助关于Java的抗锯齿实现 | jancyu2008 | 30 | 2008-07-01 23:29 |
16206 | Re:求助关于Java的抗锯齿实现 | widewindow | 335 | 2008-06-05 18:35 |
16094 | Re:求助关于Java的抗锯齿实现 | JiafanZhou | 773 | 2008-06-06 16:34 |
16565 | Re:求助关于Java的抗锯齿实现 | widewindow | 539 | 2008-06-06 17:01 |
16158 | Re:求助关于Java的抗锯齿实现 | widewindow | 322 | 2008-06-09 12:01 |
15997 | Re:求助关于Java的抗锯齿实现 | JiafanZhou | 1213 | 2008-06-09 19:24 |
16538 | Re:求助关于Java的抗锯齿实现 | widewindow | 4520 | 2008-06-11 10:50 |
15889 | Re:求助关于Java的抗锯齿实现 | JiafanZhou | 610 | 2008-06-13 15:50 |
16167 | Re:求助关于Java的抗锯齿实现 | widewindow | 558 | 2008-06-13 16:32 |
已读帖子 新的帖子 被删除的帖子 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |