List of usage examples for java.awt Graphics2D setRenderingHint
public abstract void setRenderingHint(Key hintKey, Object hintValue);
From source file:dataminning2.KmeanGraphplot.java
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); // Draw ordinate. g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); // Draw abcissa. g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); double xInc = (double) (w - 2 * PAD) / (data.length - 1); double scale = (double) (h - 2 * PAD) / 88; // Mark data points. g2.setPaint(Color.red);//ww w . ja v a 2 s. co m for (int i = 0; i < cluster0.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.BLUE); for (int i = 0; i < cluster1.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.YELLOW); for (int i = 0; i < cluster2.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } }
From source file:TextQualityDemoVALUE_TEXT_ANTIALIAS_LCD_HBGR.java
public void paintComponent(Graphics g) { Dimension d = this.getSize(); BufferedImage backBuffer = (BufferedImage) this.createImage(d.width, d.height); Graphics2D g2 = backBuffer.createGraphics(); g2.setColor(Color.WHITE);/* w w w.j a v a 2 s. c om*/ g2.fillRect(0, 0, d.width, d.height); g2.setColor(Color.BLACK); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, hintValue); g2.drawRect(0, 0, d.width - 1, d.height - 1); g2.drawString("abcdefghijklmnopqrstuvwxyz", 20, 40); g2.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 20, 60); g2.drawString("1234567890-=!@#$%^&*()_+,./<>?", 20, 80); g.drawImage(backBuffer, 0, 0, this); }
From source file:LineStyles.java
/** This method draws the example figure */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Use anti-aliasing to avoid "jaggies" in the lines g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Define the shape to draw GeneralPath shape = new GeneralPath(); shape.moveTo(xpoints[0], ypoints[0]); // start at point 0 shape.lineTo(xpoints[1], ypoints[1]); // draw a line to point 1 shape.lineTo(xpoints[2], ypoints[2]); // and then on to point 2 // Move the origin to the right and down, creating a margin g.translate(20, 40);// ww w. j a va 2 s .co m // Now loop, drawing our shape with the three different line styles for (int i = 0; i < linestyles.length; i++) { g.setColor(Color.gray); // Draw a gray line g.setStroke(linestyles[i]); // Select the line style to use g.draw(shape); // Draw the shape g.setColor(Color.black); // Now use black g.setStroke(thindashed); // And the thin dashed line g.draw(shape); // And draw the shape again. // Highlight the location of the vertexes of the shape // This accentuates the cap and join styles we're demonstrating for (int j = 0; j < xpoints.length; j++) g.fillRect(xpoints[j] - 2, ypoints[j] - 2, 5, 5); g.drawString(capNames[i], 5, 105); // Label the cap style g.drawString(joinNames[i], 5, 120); // Label the join style g.translate(150, 0); // Move over to the right before looping again } }
From source file:dk.netdesign.common.osgi.config.osgi.OCD.java
public BufferedImage scaleImage(BufferedImage img, int width, int height, Color background) { int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); if (imgWidth * height < imgHeight * width) { width = imgWidth * height / imgHeight; } else {// ww w .j a v a2s . co m height = imgHeight * width / imgWidth; } BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImage.createGraphics(); try { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setBackground(background); g.clearRect(0, 0, width, height); g.drawImage(img, 0, 0, width, height, null); } finally { g.dispose(); } return newImage; }
From source file:com.fusesource.forge.jmstest.persistence.rrd.RrdGraphPostProcessor.java
private void createThumbnail(BufferedImage image, String name, int thumbWidth, int thumbHeight) { double thumbRatio = (double) thumbWidth / (double) thumbHeight; int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); double imageRatio = (double) imageWidth / (double) imageHeight; if (thumbRatio < imageRatio) { thumbHeight = (int) (thumbWidth / imageRatio); } else {//w w w. j ava 2 s . c o m thumbWidth = (int) (thumbHeight * imageRatio); } BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null); File thumbFile = new File(getWorkDir().getAbsolutePath() + "/" + name + "-thumb.png"); try { ImageIO.write(thumbImage, "PNG", thumbFile); } catch (IOException ioe) { log().error("Error creating thumbnail for: " + name); } }
From source file:com.igormaznitsa.jhexed.values.HexSVGImageValue.java
@Override public BufferedImage makeIcon(final int width, final int height, final Path2D shape, final boolean allowAlpha) { try {//from w ww. ja v a2 s . c o m final BufferedImage img = this.image.rasterize(width, height, BufferedImage.TYPE_INT_ARGB); if (shape == null) { return img; } else { final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = result.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setClip(makeTransformedPathForSize(width, height, shape)); g.drawImage(img, 0, 0, null); g.dispose(); return result; } } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; RenderingHints rhints = g2d.getRenderingHints(); boolean antialiasOn = rhints.containsValue(RenderingHints.VALUE_ANTIALIAS_ON); System.out.println(antialiasOn); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }
From source file:FieldValidator.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); JLayer jlayer = (JLayer) c; JFormattedTextField ftf = (JFormattedTextField) jlayer.getView(); if (!ftf.isEditValid()) { Graphics2D g2 = (Graphics2D) g.create(); // Paint the red X. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = c.getWidth(); int h = c.getHeight(); int s = 8; int pad = 4; int x = w - pad - s; int y = (h - s) / 2; g2.setPaint(Color.red);//from ww w . ja v a2 s . c o m g2.fillRect(x, y, s + 1, s + 1); g2.setPaint(Color.white); g2.drawLine(x, y, x + s, y + s); g2.drawLine(x, y + s, x + s, y); g2.dispose(); } }
From source file:net.rptools.lib.image.ThumbnailManager.java
private Image createThumbnail(File file) throws IOException { // Gather info File thumbnailFile = getThumbnailFile(file); if (thumbnailFile.exists()) { return ImageUtil.getImage(thumbnailFile); }/*from www .j a v a 2s. c om*/ Image image = ImageUtil.getImage(file); Dimension imgSize = new Dimension(image.getWidth(null), image.getHeight(null)); // Test if we Should we bother making a thumbnail ? // Jamz: New size 100k (was 30k) and put in check so we're not creating thumbnails LARGER than the original... if (file.length() < 102400 || (imgSize.width <= thumbnailSize.width && imgSize.height <= thumbnailSize.height)) { return image; } // Transform the image SwingUtil.constrainTo(imgSize, Math.min(image.getWidth(null), thumbnailSize.width), Math.min(image.getHeight(null), thumbnailSize.height)); BufferedImage thumbnailImage = new BufferedImage(imgSize.width, imgSize.height, ImageUtil.pickBestTransparency(image)); Graphics2D g = thumbnailImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.drawImage(image, 0, 0, imgSize.width, imgSize.height, null); g.dispose(); // Use png to preserve transparency FileUtils.writeByteArrayToFile(thumbnailFile, ImageUtil.imageToBytes(thumbnailImage, "png")); return thumbnailImage; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; RenderingHints rhints = g2d.getRenderingHints(); boolean antialiasOn = rhints.containsValue(RenderingHints.VALUE_ANTIALIAS_ON); System.out.println(antialiasOn); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }