List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON
Object VALUE_ANTIALIAS_ON
To view the source code for java.awt RenderingHints VALUE_ANTIALIAS_ON.
Click Source Link
From source file:org.jcurl.core.swing.RockLocationDisplayBase.java
public void exportPng(File dst) throws IOException { final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = (Graphics2D) img.getGraphics(); {/* www . ja va 2s .c o m*/ final Map hints = new HashMap(); hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.addRenderingHints(hints); } this.paintComponent(g2); g2.dispose(); if (!dst.getName().endsWith(".png")) dst = new File(dst.getName() + ".png"); ImageIO.write(img, "png", dst); }
From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java
/** * Render the pie chart with the given height * // w w w . j av a 2s. c o m * @param height * The height of the resulting image * @return The pie chart rendered as an image */ public BufferedImage render(int height) { BufferedImage image = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.scale(zoom, zoom); // fill background to white g2.setColor(Color.WHITE); g2.fill(new Rectangle(totalWidth, totalHeight)); // prepare render hints g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // draw shadow image g2.drawImage(pieShadow.getImage(), 0, 0, pieShadow.getImageObserver()); double start = 0; List<Arc2D> pies = new ArrayList<>(); // pie segmente erzeugen und fuellen if (total == 0) { g2.setColor(BRIGHT_GRAY); g2.fillOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius); g2.setColor(Color.WHITE); g2.drawOval(centerX - radius, centerY - radius, 2 * radius, 2 * radius); } else { for (Segment s : segments) { double portionDegrees = s.getPortion() / total; Arc2D pie = paintPieSegment(g2, start, portionDegrees, s.getColor()); if (withSubSegments) { double smallRadius = radius * s.getSubSegmentRatio(); paintPieSegment(g2, start, portionDegrees, smallRadius, s.getColor().darker()); } start += portionDegrees; // portion degree jetzt noch als String (z.B. "17.3%" oder "20%" zusammenbauen) String p = String.format(Locale.ENGLISH, "%.1f", Math.rint(portionDegrees * 1000) / 10.0); p = removeSuffix(p, ".0"); // evtl. ".0" bei z.B. "25.0" abschneiden (-> "25") s.setPercent(p + "%"); pies.add(pie); } // weissen Rahmen um die pie segmente zeichen g2.setColor(Color.WHITE); for (Arc2D pie : pies) { g2.draw(pie); } } // Legende zeichnen renderLegend(g2); // "xx%" Label direkt auf die pie segmente zeichen g2.setColor(Color.WHITE); float fontSize = 32f; g2.setFont(NORMALFONT.deriveFont(fontSize).deriveFont(Font.BOLD)); start = 0; for (Segment s : segments) { if (s.getPortion() < 1E-6) { continue; // ignore segments with portions that are extremely small } double portionDegrees = s.getPortion() / total; double angle = start + portionDegrees / 2; // genau in der Mitte des Segments double xOffsetForCenteredTxt = 8 * s.getPercent().length(); // assume roughly 8px per char int x = (int) (centerX + 0.6 * radius * Math.sin(2 * Math.PI * angle) - xOffsetForCenteredTxt); int y = (int) (centerY - 0.6 * radius * Math.cos(2 * Math.PI * angle) + fontSize / 2); g2.drawString(s.getPercent(), x, y); start += portionDegrees; } return image; }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
/** * Sets high-quality rendering hints on the current Graphics2D. *//* w w w. j av a2 s . c o m*/ private void setRenderingHints() { graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }
From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java
/** * Process a GET request./*from www .j a v a 2 s . c o m*/ * * @param request the request. * @param response the response. * * @throws ServletException if there is a servlet related problem. * @throws IOException if there is an I/O problem. */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OutputStream out = response.getOutputStream(); try { String type = request.getParameter("type"); String format = request.getParameter("format"); String eid = request.getParameter("eid"); JFreeChart chart = null; if ("pie".equalsIgnoreCase(type)) { chart = createPieChart(); } else if ("bar".equalsIgnoreCase(type)) { chart = createBarChart(); } else if ("time".equalsIgnoreCase(type)) { chart = createTimeSeriesChart(); } else if ("exp".equalsIgnoreCase(type)) { chart = createXYChart(eid); } else if ("wall".equalsIgnoreCase(type)) { chart = createWallclockChart(eid); } else { chart = null; } // Render if (chart != null) { if ("svg".equalsIgnoreCase(format)) { response.setContentType("image/svg+xml"); writeChartAsSVG(out, chart, 600, 500); } else { response.setContentType("image/png"); // force aliasing of the rendered content.. chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ChartUtilities.writeChartAsPNG(out, chart, 600, 500); } } } catch (Exception e) { System.err.println(e.toString()); e.printStackTrace(); } finally { out.close(); } }
From source file:DrawShapes_2008.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; // Paint a gradient for the sky GradientPaint background = new GradientPaint(0f, 0f, Color.GRAY.darker(), 0f, (float) getHeight(), Color.GRAY.brighter()); g2d.setPaint(background);/* ww w .jav a2 s . c o m*/ g2d.fillRect(0, 0, getWidth(), 4 * getHeight() / 5); // Paint a gradient for the ground background = new GradientPaint(0f, (float) 4 * getHeight() / 5, Color.BLACK, 0f, (float) getHeight(), Color.GRAY.darker()); g2d.setPaint(background); g2d.fillRect(0, 4 * getHeight() / 5, getWidth(), getHeight() / 5); // Enable anti-aliasing to get smooth outlines g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Iterate through all of the current shapes for (Shape shape : shapes) { // Get the bounds to compute the RadialGradient properties Rectangle rect = shape.getBounds(); Point2D center = new Point2D.Float(rect.x + (float) rect.width / 2.0f, rect.y + (float) rect.height / 2.0f); float radius = (float) rect.width / 2.0f; float[] dist = { 0.1f, 0.9f }; Color[] colors = { Color.WHITE, Color.BLACK }; // Create and set a RadialGradient centered on the object, // going from white at the center to black at the edges RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2d.setPaint(paint); // Finally, render our shape g2d.fill(shape); } }
From source file:haven.Utils.java
static void AA(Graphics g) { java.awt.Graphics2D g2 = (java.awt.Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); }
From source file:org.uva.itast.blended.omr.pages.PDFPageImage.java
/** * Mtodo que lee una imagen pdf y la transforma en un objeto de tipo * BufferedImage reescalado// w ww . java 2s. co m * * @param page * @return img_pdf * @throws InterruptedException * @throws Exception */ private BufferedImage renderFullPageImage(PDFPage page) throws InterruptedException { BufferedImage img_pdf = null; // bufferedimage para almacenar la imagen // se elige el ancho y el alto de la imagen int resizeWidth = OMRProcessor._PAGE_WIDTH_PIXELS; int resizeHeight = OMRProcessor._PAGE_HEIGHT_PIXELS; img_pdf = new BufferedImage(resizeWidth, resizeHeight, BufferedImage.TYPE_INT_RGB); // se configura la imagen con las // medidas especificas y en // escala de grises Graphics2D g2 = img_pdf.createGraphics(); // se crea un objeto grfico // en dos dimensiones g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); PDFRenderer renderer = new PDFRenderer(page, g2, new Rectangle(0, 0, OMRProcessor._PAGE_WIDTH_PIXELS, OMRProcessor._PAGE_HEIGHT_PIXELS), null, Color.RED); // se // renderiza // la // imgen page.waitForFinish(); renderer.run(); img_pdf.createGraphics().drawImage(img_pdf, 0, 0, resizeWidth, resizeHeight, null); // por ltimo se dibuja la imagen return img_pdf; }
From source file:org.kchine.r.server.impl.RGraphicsPanelRemote.java
public synchronized void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize();/*from ww w . j a v a2 s . c om*/ if (!d.equals(_lastSize)) { _lastResizeTime = System.currentTimeMillis(); _lastSize = d; return; } else { } if (forceAntiAliasing) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } int i = 0, j = _l.size(); g.setFont(_gs.f); g.setClip(0, 0, d.width, d.height); // reset clipping rect g.setColor(Color.white); g.fillRect(0, 0, d.width, d.height); while (i < j) { GDObject o = (GDObject) _l.elementAt(i++); o.paint(this, _gs, g); } }
From source file:ClipImage.java
public Graphics2D createDemoGraphics2D(Graphics g) { Graphics2D g2 = null;/*from ww w.j a v a 2 s .c o m*/ if (offImg == null || offImg.getWidth() != w || offImg.getHeight() != h) { offImg = (BufferedImage) createImage(w, h); newBufferedImage = true; } if (offImg != null) { g2 = offImg.createGraphics(); g2.setBackground(getBackground()); } // .. set attributes .. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // .. clear canvas .. g2.clearRect(0, 0, w, h); return g2; }
From source file:JXTransformer.java
public void paint(Graphics g) { //repaint the whole transformer in case the view component was repainted Rectangle clipBounds = g.getClipBounds(); if (clipBounds != null && !clipBounds.equals(visibleRect)) { repaint();//from www . j ava 2 s. co m } //clear the background g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); if (view != null && at.getDeterminant() != 0) { Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); Rectangle bounds = getBounds(); //don't forget about insets bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; double centerX1 = bounds.getCenterX(); double centerY1 = bounds.getCenterY(); Rectangle tb = getTransformedSize(); double centerX2 = tb.getCenterX(); double centerY2 = tb.getCenterY(); //set antialiasing by default g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (renderingHints != null) { g2.addRenderingHints(renderingHints); } //translate it to the center of the view component again double tx = centerX1 - centerX2 - getX(); double ty = centerY1 - centerY2 - getY(); g2.translate((int) tx, (int) ty); g2.transform(at); view.paint(g2); g2.dispose(); } //paint the border paintBorder(g); }