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 paintComponent(Graphics g) { if (image == null) { image = createImage(getSize().width, getSize().height); graphics2D = (Graphics2D) image.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); clear();//www . j a v a 2s .co m } g.drawImage(image, 0, 0, null); }
From source file:AntiAlias.java
/** 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_RGB); 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);//from ww w . jav a2 s . c o m // 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, // Anti-alias! RenderingHints.VALUE_ANTIALIAS_ON); // 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, 62, 32); // 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); }
From source file:ShowOff.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); drawBackground(g2);// w w w.ja v a 2 s . c om drawImageMosaic(g2); drawText(g2); }
From source file:net.dv8tion.jda.utils.AvatarUtil.java
private static BufferedImage resize(BufferedImage originalImage) { BufferedImage resizedImage = new BufferedImage(SIZE, SIZE, 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(originalImage, 0, 0, SIZE, SIZE, Color.white, null); g.dispose();/*from w ww.j a v a 2 s . c o m*/ return resizedImage; }
From source file:savant.view.variation.swing.VariantMap.java
@Override public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Paint a gradient from top to bottom int h = getHeight(); int w = getWidth(); GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0, h, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM)); g2.setPaint(gp0);//from w w w.ja v a 2 s . c o m g2.fillRect(0, 0, w, h); List<VariantRecord> data = controller.getData(); if (data != null && !data.isEmpty()) { double boxTop = Double.NaN; double boxBottom = Double.NaN; Range browseRange = LocationController.getInstance().getRange(); int participantCount = controller.getParticipantCount(); unitHeight = (double) h / data.size(); unitWidth = (double) w / participantCount; boolean gappable = unitHeight > GAP_HEIGHT * 2.0; ColourScheme cs = new ColourScheme(ColourKey.A, ColourKey.C, ColourKey.G, ColourKey.T, ColourKey.INSERTED_BASE, ColourKey.DELETED_BASE, ColourKey.N); ColourAccumulator accumulator = new ColourAccumulator(cs); double y = 0.0; double topGap = 0.0; for (int i = 0; i < data.size(); i++) { VariantRecord varRec = data.get(i); double bottomGap = 0.0; if (gappable && i + 1 < data.size()) { VariantRecord nextRec = data.get(i + 1); if (nextRec.getPosition() - varRec.getPosition() > 1) { bottomGap = GAP_HEIGHT * 0.5; } } if (Double.isNaN(boxTop) && browseRange.getFrom() <= varRec.getPosition() && browseRange.getTo() >= varRec.getPosition()) { boxTop = y + topGap; boxBottom = boxTop + unitHeight; } else if (varRec.getPosition() <= browseRange.getTo()) { boxBottom = y + unitHeight - bottomGap; } double x = 0.0; for (int j = 0; j < participantCount; j++) { VariantTrackRenderer.accumulateZygoteShapes(varRec.getVariantsForParticipant(j), accumulator, new Rectangle2D.Double(x, y + topGap, unitWidth, unitHeight - topGap - bottomGap)); x += unitWidth; } topGap = bottomGap; y += unitHeight; } accumulator.fill(g2); if (gappable) { drawGapSizes(g2); } else { // Not enough room to draw gaps, so just label the axes. labelVerticalAxis(g2); } g2.setClip(null); g2.setColor(Color.BLUE); g2.draw(new Rectangle2D.Double(0.0, boxTop, w - 1.0, boxBottom - boxTop - 1.0)); } }
From source file:electroStaticUI.Save.java
/** * Save chart as SVG file.//from www . j av a2 s . co m * Required libs: Apache Batik (batik-svggen.jar, batik-dom.jar, dom.jar). * * @param chart JFreeChart to save. * @param fileName Name of file to save chart in. * @param width Width of chart graphic. * @param height Height of chart graphic. * @return Final file name used. * @throws IOException if failed. * * To Do: Add a save/open method for saving a file native to this application. It should save the users current charge distribution * to be re-loaded at a later time. */ static public final String saveChartToSVG(final JFreeChart chart, String fileName, final int width, final int height) throws IOException { String result = null; if (chart != null) { if (fileName == null) { final String chartTitle = chart.getTitle().getText(); if (chartTitle != null) { fileName = chartTitle; } else { fileName = "chart"; } } result = fileName + ".svg"; final DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); final Document document = domImpl.createDocument(null, "svg", null); final SVGGraphics2D svgGenerator = new SVGGraphics2D(document); // svgGenerator.getGeneratorContext().setEmbeddedFontsOn(true); //embed fonts //set anti-aliasing bug fix for SVG generator: //setting rendering hints of svgGenerator doesn't help as it seems to use the rendering hints from the chart final boolean antiAlias = chart.getAntiAlias(); final RenderingHints rh = chart.getRenderingHints(); if (antiAlias) { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); //fix } else { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); //fix } // svgGenerator.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // svgGenerator.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); // svgGenerator.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // svgGenerator.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); // svgGenerator.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // svgGenerator.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height), new ChartRenderingInfo()); //undo anti-aliasing bugfix settings for chart to use correct settings: if (antiAlias) { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } final boolean useCSS = true; Writer out = null; try { out = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(new File(result), false)), "iso-8859-1"); //UTF-8 svgGenerator.stream(out, useCSS); } finally { svgGenerator.dispose(); IOUtils.closeQuietly(out); } } //else: input unavailable return result; }
From source file:CustomStrokes.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Get a shape to work with. Here we'll use the letter B Font f = new Font("Serif", Font.BOLD, 200); GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "B"); Shape shape = gv.getOutline(); // Set drawing attributes and starting position g.setColor(Color.black);// ww w . j a v a 2 s . c o m g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.translate(10, 175); // Draw the shape once with each stroke for (int i = 0; i < strokes.length; i++) { g.setStroke(strokes[i]); // set the stroke g.draw(shape); // draw the shape g.translate(140, 0); // move to the right } }
From source file:gui.DendrogramChart.java
ChartPanel getChartPanel(Dendrogram d, boolean log) { JFreeChart chart = ChartFactory.createXYLineChart(null, "Similarity", "No. of Groups", null, PlotOrientation.VERTICAL, true, true, false); setChartData(chart, log);// ww w .j av a2s. co m RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); chart.setRenderingHints(rh); chart.removeLegend(); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(255, 255, 220)); plot.setDomainGridlinePaint(new Color(128, 128, 128)); plot.setRangeGridlinePaint(new Color(128, 128, 128)); if (log == false) { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setNumberFormatOverride(new DecimalFormat("0")); rangeAxis.setLabelFont(Prefs.labelFont); } else { // LogarithmicAxis logXAxis = new LogarithmicAxis("Similarity"); // logXAxis.setAllowNegativesFlag(true); LogarithmicAxis logYAxis = new LogarithmicAxis("No. Of Groups"); logYAxis.setAllowNegativesFlag(false); // plot.setDomainAxis(logXAxis); plot.setRangeAxis(logYAxis); } ChartPanel chartPanel = new ChartPanel(chart); // chartPanel.setPopupMenu(null); return chartPanel; }
From source file:TransformScale.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);/*from w ww .java2 s . c om*/ // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. g2.transform(AffineTransform.getScaleInstance(3, 3)); // Draw the "new" shapes in dashed. g2.transform(AffineTransform.getTranslateInstance(75, 75)); Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:TransformShear.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);// ww w . java2 s. c o m // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. AffineTransform sat = AffineTransform.getTranslateInstance(150, 0); sat.shear(-.5, 0); g2.transform(sat); // Draw the "new" shapes in dashed. g2.transform(AffineTransform.getTranslateInstance(75, 75)); Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }