List of usage examples for java.awt RenderingHints KEY_ANTIALIASING
Key KEY_ANTIALIASING
To view the source code for java.awt RenderingHints KEY_ANTIALIASING.
Click Source Link
From source file:Main.java
public void render(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.WHITE);// ww w. java 2s. co m Font font = new Font("Verdana", Font.PLAIN, 20); g2d.setFont(font); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); FontMetrics fm = g2d.getFontMetrics(); String option = "This is a test"; int x = (getWidth() - fm.stringWidth(option)) / 2; int y = ((getHeight() - fm.getHeight()) / 2); g2d.drawString(option, x, y + fm.getAscent()); g2d.drawRect((int) x - 20, (int) y - 10, (int) fm.stringWidth(option) + 40, (int) fm.getHeight() + 20); }
From source file:CombiningShapes.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String option = (String) mOptions.getSelectedItem(); if (option.equals("outline")) { // draw the outlines and return. g2.draw(mShapeOne);//from ww w.ja va 2 s. com g2.draw(mShapeTwo); return; } // Create Areas from the shapes. Area areaOne = new Area(mShapeOne); Area areaTwo = new Area(mShapeTwo); // Combine the Areas according to the selected option. if (option.equals("add")) areaOne.add(areaTwo); else if (option.equals("intersection")) areaOne.intersect(areaTwo); else if (option.equals("subtract")) areaOne.subtract(areaTwo); else if (option.equals("exclusive or")) areaOne.exclusiveOr(areaTwo); // Fill the resulting Area. g2.setPaint(Color.orange); g2.fill(areaOne); // Draw the outline of the resulting Area. g2.setPaint(Color.black); g2.draw(areaOne); }
From source file:com.taunova.app.libview.components.ImageHelpers.java
public static Image getScaledImage(BufferedImage image, int width) { Dimension d = getScaledDimension(image, width); Image scaledImage = image.getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH); BufferedImage resizedImage = null; final boolean OPTIMIZE_SCALE = true; if (OPTIMIZE_SCALE) { ResampleOp resampleOp = new ResampleOp(100, 200); resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal); resizedImage = resampleOp.filter(image, null); } else {//from w w w. j a v a2s . c o m resizedImage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(scaledImage, 0, 0, d.width, d.height, null); g.dispose(); } return resizedImage; }
From source file:Hypnosis1.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Shape s = createShape();// w w w. j a va 2 s. com g2.setPaint(paint); g2.fill(s); g2.setPaint(Color.white); g2.draw(s); }
From source file:MainClass.java
public void paint(Graphics g) { BufferedImage bim;/*from w ww .ja va2s.com*/ TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }
From source file:GeneralPathDemo.java
public void paintComponent(Graphics g) { // super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (firstTime) { Dimension dim = getSize(); int w = dim.width; int h = dim.height; oddShape = createPath();//from w w w. ja v a2 s.co m area = new Rectangle(w, h); bi = (BufferedImage) createImage(w, h); big = bi.createGraphics(); big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); firstTime = false; } // Clears the shape that was previously drawn. big.setColor(Color.white); big.fillRect(0, 0, area.width, area.height); big.setColor(Color.magenta); big.setStroke(new BasicStroke(3.0f)); big.draw(oddShape); // Draws the buffered image to the screen. g2.drawImage(bi, 0, 0, this); }
From source file:FontPaint.java
public void paintComponent(Graphics g) { super.paintComponent(g); setBackground(Color.white);/*from w w w.ja v a 2s .c om*/ int width = getSize().width; int height = getSize().height; Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); FontRenderContext frc = g2.getFontRenderContext(); Font f = new Font("Helvetica", 1, 60); String s = new String("Java Source and Support."); TextLayout textTl = new TextLayout(s, f, frc); AffineTransform transform = new AffineTransform(); Shape outline = textTl.getOutline(null); Rectangle outlineBounds = outline.getBounds(); transform = g2.getTransform(); transform.translate(width / 2 - (outlineBounds.width / 2), height / 2 + (outlineBounds.height / 2)); g2.transform(transform); g2.setColor(Color.blue); g2.draw(outline); g2.setClip(outline); }
From source file:Highlights.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); String s = "Drag the text to highlight Java Source and Support."; Font font = new Font("Serif", Font.PLAIN, 32); if (textLayout == null) { FontRenderContext frc = g2.getFontRenderContext(); textLayout = new TextLayout(s, font, frc); }//from w w w. ja va 2 s .c om // Draw the highlight. if (firstHit != null && secondHit != null) { Shape base = textLayout.getLogicalHighlightShape(firstHit.getInsertionIndex(), secondHit.getInsertionIndex()); AffineTransform at = AffineTransform.getTranslateInstance(x, y); Shape highlight = at.createTransformedShape(base); g2.setPaint(Color.white); g2.fill(highlight); } g2.setPaint(Color.black); textLayout.draw(g2, x, y); }
From source file:Main.java
public void paint(Graphics g) { BufferedImage bim;//from w ww . j a v a 2 s .c o m TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); System.out.println(tp.getImage()); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }
From source file:Main.java
public void paint(Graphics g) { BufferedImage bim;//from w ww . j a v a 2s . c om TexturePaint tp; String mesg = "www.java2s.com"; Font myFont = new Font("Lucida Regular", Font.BOLD, 72); Color[] colors = { Color.red, Color.blue, Color.yellow, }; int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); System.out.println(tp.getAnchorRect()); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setPaint(tp); g2d.setFont(myFont); g2d.drawString(mesg, 20, 100); }