Example usage for java.awt.image BufferedImage BufferedImage

List of usage examples for java.awt.image BufferedImage BufferedImage

Introduction

In this page you can find the example usage for java.awt.image BufferedImage BufferedImage.

Prototype

public BufferedImage(int width, int height, int imageType) 

Source Link

Document

Constructs a BufferedImage of one of the predefined image types.

Usage

From source file:com.googlecode.fightinglayoutbugs.helpers.ImageHelper.java

public static BufferedImage pixelsToImage(boolean[][] pixels) {
    if (pixels == null) {
        return null;
    }// www.j  a  va  2 s  .c  o  m
    int w = pixels.length;
    if (w > 0) {
        int h = pixels[0].length;
        if (h > 0) {
            BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            for (int x = 0; x < w; ++x) {
                boolean[] column = pixels[x];
                for (int y = 0; y < h; ++y) {
                    image.setRGB(x, y, column[y] ? 0 : 0xFFFFFF);
                }
            }
            return image;
        } else {
            throw new IllegalArgumentException("pixels[0].length must not be 0.");
        }
    } else {
        throw new IllegalArgumentException("pixels.length must not be 0.");
    }
}

From source file:org.n52.io.type.quantity.handler.img.ChartIoHandler.java

private BufferedImage createImage() {
    IoParameters parameters = getParameters();
    int width = parameters.getWidth();
    int height = parameters.getHeight();
    BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D chartGraphics = chartImage.createGraphics();
    chartGraphics.fillRect(0, 0, width, height);
    chartGraphics.setColor(Color.WHITE);

    jFreeChart.setTextAntiAlias(true);//  w  w w  . j  a va  2 s. c o m
    jFreeChart.setAntiAlias(true);
    if (jFreeChart.getLegend() != null) {
        jFreeChart.getLegend().setFrame(BlockBorder.NONE);
    }
    jFreeChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height));
    return chartImage;
}

From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java

/**
 * @param observationCollection//from  w  w  w. j av a 2  s. com
 * @param screenW
 * @param screenH
 * @param bbox
 * @param selectedFeatures
 *        the Features of Interest for which a chart shall be renderered.
 */
public StaticVisualization renderLayer(OXFFeatureCollection observationCollection, ParameterContainer paramCon,
        int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures) {
    if (selectedFeaturesCache == null) {
        selectedFeaturesCache = selectedFeatures;
    }

    // before starting to render --> run garbageCollection
    Runtime.getRuntime().gc();
    LOGGER.info("Garbage Collection done.");
    // --

    String[] observedProperties;
    // which observedProperty has been used?:
    ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty");
    if (observedPropertyPS.hasMultipleSpecifiedValues()) {
        observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class);
    } else if (observedPropertyPS.hasSingleSpecifiedValue()) {
        observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() };
    } else {
        throw new IllegalArgumentException("no observedProperties found.");
    }

    // find tuples:
    if (obsValues4FOI == null) {
        obsValues4FOI = new ObservationSeriesCollection(observationCollection, selectedFeaturesCache,
                observedProperties, true);
    }

    ContextBoundingBox contextBBox = new ContextBoundingBox(bbox);

    BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();

    // draw white background:
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, screenW, screenH);

    g.setColor(Color.BLACK);

    for (OXFFeature chartFeature : selectedFeaturesCache) {

        //
        // CACHING: create Plot for each "chart feature" and add it to the cache:
        //
        if (!chartCache.containsKey(chartFeature)) {
            Map<ITimePosition, ObservedValueTuple> timeMap = obsValues4FOI.getAllTuples(chartFeature);

            // draw a chart if there are tuples for the chartFeature available:
            if (timeMap != null) {
                XYPlot chart = drawChart4FOI(chartFeature.getID(), timeMap);
                chartCache.put(chartFeature, chart);
            }
        }

        //
        // draw the plots (which are in the cache):
        //
        Point pRealWorld = (Point) chartFeature.getGeometry();

        java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW,
                screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y));
        XYPlot cachedPlot = (XYPlot) chartCache.get(chartFeature);

        // if there is a plot in the cache for the chartFeature -> draw it:
        if (cachedPlot != null) {
            cachedPlot.getRangeAxis().setRange((Double) obsValues4FOI.getMinimum(0),
                    (Double) obsValues4FOI.getMaximum(0));

            cachedPlot.draw(g,
                    new Rectangle2D.Float(pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT),
                    null, null, null);
        } else {
            g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT);
        }

        // draw point of feature:
        g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2),
                FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT);

    }

    return new StaticVisualization(image);
}