Example usage for java.awt RenderingHints VALUE_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON

Introduction

In this page you can find the example usage for java.awt RenderingHints VALUE_ANTIALIAS_ON.

Prototype

Object VALUE_ANTIALIAS_ON

To view the source code for java.awt RenderingHints VALUE_ANTIALIAS_ON.

Click Source Link

Document

Antialiasing hint value -- rendering is done with antialiasing.

Usage

From source file:org.limy.eclipse.qalab.outline.sequence.SequenceImageCreator.java

/**
 * V?[PX?}?? layoutData, pngFile ?o?B//from  www  .j  a v  a 2 s  . c  o  m
 * @param root V?[PX?}Bean
 * @throws IOException I/OO
 * @throws ParserException 
 */
private void writeSequence(SequenceBean root) throws IOException, ParserException {
    StringWriter out = new StringWriter();
    Context context = new VelocityContext();
    context.put("root", root);
    VelocitySupport.write(new File(LimyQalabPlugin.getDefault().getPluginRoot(), "resource/sequence/index.vm")
            .getAbsolutePath(), context, out);
    File txtFile = LimyQalabUtils.createTempFile(env.getProject(), "sequence.txt");
    pngFile = LimyQalabUtils.createTempFile(env.getProject(), "sequence.png");
    FileUtils.writeByteArrayToFile(txtFile, out.toString().getBytes());

    Parser parser = ParserFactory.getInstance().getDefaultParser();
    NodeFactory nodeFactory = ParserFactory.getInstance().getNodeFactoryForParser(parser);
    Diagram diagram = new Diagram(parser, nodeFactory);

    PushbackReader reader = new PushbackReader(new FileReader(txtFile));
    try {
        diagram.parse(reader);
    } finally {
        reader.close();
    }

    Model model = new Model(new ExceptionHandler() {
        public void exception(Exception e) {
            e.printStackTrace();
        }
    }, diagram);

    BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = bi.createGraphics();
    layoutData = new LayoutData(new SwingStringMeasure(graphics));
    diagram.layout(layoutData);

    int height = layoutData.getHeight();
    int width = layoutData.getWidth();

    BufferedImage png = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D pngGraphics = png.createGraphics();
    pngGraphics.setClip(0, 0, width, height);
    Map<Key, Object> hintsMap = new HashMap<Key, Object>();
    hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    pngGraphics.addRenderingHints(hintsMap);
    pngGraphics.setBackground(Prefs.getColorValue(Prefs.BACKGROUND_COLOR));
    pngGraphics.fillRect(0, 0, width, height);

    SwingPainter painter = new SwingPainter();
    painter.setGraphics(pngGraphics);
    model.layout(layoutData);
    layoutData.paint(painter);

    ImageIO.write(png, "png", pngFile);
}

From source file:business.ImageManager.java

public void doDrawCircle(Graphics2D big, int x, int y, Color color) {
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(new BasicStroke());
    big.setColor(color);// ww  w.j ava2 s .  c  o m

    //draw on graph
    big.drawOval(x, x, y, y);
}

From source file:org.squidy.designer.shape.VisualShape.java

@Override
protected final void paint(PPaintContext paintContext) {
    super.paint(paintContext);

    Graphics2D g = paintContext.getGraphics();

    // Set default font.
    g.setFont(internalFont);/*from  w  w w. j av  a 2  s .  c  o m*/

    //      if (!renderingHintsSet) {
    if (isRenderPrimitive()) {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    } else {
        // Use anti aliasing -> May slow down performance.
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }
    //         renderingHintsSet = true;
    //      }

    // Paint the shapes visual representation.
    paintShape(paintContext);

    // Allows visual debugging if enabled.
    if (DebugConstants.ENABLED) {
        paintDebug(paintContext);
    }
}

From source file:org.jas.util.ImageUtils.java

public Image resize(Image image, int width, int height) {
    BufferedImage bufferedImage = (BufferedImage) image;
    int type = bufferedImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : bufferedImage.getType();
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    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(image, 0, 0, width, height, null);
    g.dispose();/*www .  j  a  va  2s . co m*/
    return resizedImage;
}

From source file:com.salesmanager.core.util.ProductImageUtil.java

public BufferedImage resize(BufferedImage image, int width, int height) {
    int type = image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : image.getType();
    BufferedImage resizedImage = new BufferedImage(width, height, type);
    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(image, 0, 0, width, height, null);
    g.dispose();//from www .j av  a  2  s .  com
    return resizedImage;
}

From source file:org.eclipse.titanium.graph.visualization.GraphHandler.java

/**
 * Exports the graph set for this class to a PNG file
 * /*from  w w w .ja va 2s. c  o m*/
 * @param path
 *            : The PNG file's path
 * @param mode
 *            : The way of export, see {@link GraphHandler}
 *            <code>public static</code> fields for possible values (EXPORT_
 *            named fields)
 * @param size
 *            : This parameter sets the size of the exported image in pixels
 * @throws Exception
 *             on file handling error
 */
public void saveToImage(final String path, final ImageExportType mode) throws BadLayoutException {
    if (layout == null || actVisualisator == null) {
        throw new BadLayoutException("Either the layout or the visuaizer is not set (is null)",
                ErrorType.NO_OBJECT);
    }

    VisualizationViewer<NodeDescriptor, EdgeDescriptor> tempVisualisator = null;
    Dimension size = null;
    switch (mode) {
    case EXPORT_SEEN_GRAPH: {
        tempVisualisator = actVisualisator;
        size = actVisualisator.getPreferredSize();
    }
        break;
    case EXPORT_WHOLE_GRAPH: {
        layout = actVisualisator.getGraphLayout();
        if (size == null) {
            size = new Dimension(layout.getSize().width, layout.getSize().height);
        }

        final Transformer<NodeDescriptor, Point2D> trf = new Transformer<NodeDescriptor, Point2D>() {
            @Override
            public Point2D transform(final NodeDescriptor v) {
                return layout.transform(v);
            }
        };

        tempVisualisator = new VisualizationViewer<NodeDescriptor, EdgeDescriptor>(
                new LayoutBuilder(g, Layouts.LAYOUT_STATIC, size).transformer(trf).build());
        tempVisualisator.setPreferredSize(size);
        tempVisualisator.setSize(size);
        tempVisualisator.getRenderContext().setVertexLabelTransformer(NODE_LABELER);

        final GraphRenderer<NodeDescriptor, EdgeDescriptor> rnd = new GraphRenderer<NodeDescriptor, EdgeDescriptor>(
                NODE_LABELER, tempVisualisator.getPickedVertexState(), tempVisualisator.getPickedEdgeState());
        setNodeRenderer(rnd, tempVisualisator);
        tempVisualisator.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
        tempVisualisator.setBackground(Color.white);
        tempVisualisator.setDoubleBuffered(false);
    }
        break;
    case EXPORT_SATELLITE: {
        tempVisualisator = satView;
        size = tempVisualisator.getSize();
    }
        break;
    default:
        ErrorReporter.logError("Unexpected image export type " + mode);
        return;
    }

    BufferedImage image;
    final GUIErrorHandler errorHandler = new GUIErrorHandler();
    try {
        image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
    } catch (OutOfMemoryError e) {
        final long needed = (long) size.width * (long) size.height * 4;
        String temp;
        if (needed < 1024) {
            temp = needed + " bytes";
        } else if (needed < 1024 * 1024) {
            temp = needed / 1024 + " Kbytes";
        } else {
            temp = needed / 1024 / 1024 + " Mbytes";
        }
        final String errorText = "Could not save an image of " + size.width + "*" + size.height
                + " size as there was not enough free memory (" + temp + ")";
        errorHandler.reportErrorMessage(errorText);
        ErrorReporter.logExceptionStackTrace(errorText, e);
        return;
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    tempVisualisator.paint(g2);
    g2.dispose();
    try {
        ImageIO.write(image, "png", new File(path));
    } catch (IOException e) {
        final String message = "Error while writing to file" + path;
        ErrorReporter.logExceptionStackTrace(message, e);
        errorHandler.reportException(message, e);
    }
}

From source file:com.AandR.beans.plotting.imagePlotPanel.CanvasPanel.java

/**
 *
 *//*w  ww .  ja  v  a  2s.c  om*/
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.GRAY);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (bufferedImage != null) {
        scaleGraphicsContext(g2);
        g2.drawImage(bufferedImage, 0, 0, null);
        drawTextBoxes(g2);
    }
}

From source file:ala.soils2sat.DrawingUtils.java

public static void drawRoundedRect(Graphics g, int left, int top, int right, int bottom) {
    Graphics2D g2d = (Graphics2D) g;
    g.drawLine(left + cornerSize, top, right - cornerSize, top);
    g.drawLine(left + cornerSize, bottom, right - cornerSize, bottom);
    g.drawLine(left, top + cornerSize, left, bottom - cornerSize);
    g.drawLine(right, top + cornerSize, right, bottom - cornerSize);
    final Object previousAntiAliasingHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Stroke previousStroke = g2d.getStroke();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    try {//from  w  w w .ja v  a 2  s .co  m
        g.drawLine(left, top + cornerSize, left + cornerSize, top);
        g.drawLine(left, bottom - cornerSize, left + cornerSize, bottom);
        g.drawLine(right, top + cornerSize, right - cornerSize, top);
        g.drawLine(right, bottom - cornerSize, right - cornerSize, bottom);
    } finally {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, previousAntiAliasingHint);
        g2d.setStroke(previousStroke);
    }
}

From source file:anl.verdi.plot.jfree.XYBlockRenderer.java

/**
 * Draws the block representing the specified item.
 *
 * @param g2             the graphics device.
 * @param state          the state./*from w w w.j av  a  2s  .  c  o m*/
 * @param dataArea       the data area.
 * @param info           the plot rendering info.
 * @param plot           the plot.
 * @param domainAxis     the x-axis.
 * @param rangeAxis      the y-axis.
 * @param dataset        the dataset.
 * @param series         the series index.
 * @param item           the item index.
 * @param crosshairState the crosshair state.
 * @param pass           the pass index.
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = 0.0;
    double max = paintScale.getUpperBound();
    double min = paintScale.getLowerBound();

    if (dataset instanceof XYZDataset)
        z = ((XYZDataset) dataset).getZValue(series, item);

    //NOTE: so to get the max/min color instead of unknown (Qun He, UNC, 03/19/2009)
    if (z > max)
        z = max;

    if (z < min)
        z = min;

    Color p = (Color) this.paintScale.getPaint(z);

    double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea,
            plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea,
            plot.getRangeAxisEdge());
    Rectangle2D block;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                Math.abs(xx0 - xx1));
    } else {
        block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                Math.abs(yy1 - yy0));
    }
    g2.setColor(p);
    g2.fill(block);

    if (gridLinesEnabled) {
        boolean aaOn = false;
        if (g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING) == RenderingHints.VALUE_ANTIALIAS_ON) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            aaOn = true;
        }
        g2.setPaint(gridLineColor);
        g2.setStroke(gridLineStroke);
        g2.draw(block);
        if (aaOn)
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    } else {
        g2.setStroke(basicStroke);
        g2.draw(block);
    }
}

From source file:com.salesmanager.core.util.ProductImageUtil.java

public BufferedImage blurImage(BufferedImage image) {
    float ninth = 1.0f / 9.0f;
    float[] blurKernel = { ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth, ninth };
    Map<Key, Object> map = new HashMap<Key, Object>();
    map.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    map.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    map.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    RenderingHints hints = new RenderingHints(map);
    BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, hints);
    return op.filter(image, null);
}