Example usage for java.awt.image BufferedImage getData

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

Introduction

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

Prototype

public Raster getData() 

Source Link

Document

Returns the image as one large tile.

Usage

From source file:org.esa.snap.rcp.statistics.DensityPlotPanel.java

private static byte[] getValidData(BufferedImage image) {
    if (image != null && image.getColorModel() instanceof IndexColorModel
            && image.getData().getDataBuffer() instanceof DataBufferByte) {
        return ((DataBufferByte) image.getData().getDataBuffer()).getData();
    }/*from w w  w. j a v a  2s .c  o m*/
    return null;
}

From source file:net.mindengine.galen.components.mocks.driver.MockedDriver.java

@Override
public <X> X getScreenshotAs(OutputType<X> xOutputType) throws WebDriverException {
    if (xOutputType.equals(OutputType.FILE)) {
        return (X) new File(getClass().getResource("/mocks/pages/screenshot.png").getFile());
    } else if (xOutputType.equals(OutputType.BYTES)) {
        File file = new File(getClass().getResource("/mocks/pages/screenshot.png").getFile());

        BufferedImage image = null;
        try {//from w  w w  .j a  va 2 s  .  co m
            image = Rainbow4J.loadImage(file.getAbsolutePath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return (X) ((DataBufferByte) image.getData().getDataBuffer()).getData();

    } else
        throw new RuntimeException("Cannot make screenshot");
}

From source file:com.alibaba.simpleimage.codec.jpeg.JPEGDecoderFunctionTest.java

protected void compareImage(String name, BufferedImage left, BufferedImage right, boolean ignoreError)
        throws Exception {
    if (left.getWidth() != right.getWidth() || left.getHeight() != right.getHeight()) {
        assertTrue("size not equal", false);
    }//from   w w w .  java  2 s.co  m

    Raster leftRaster = left.getData();
    Raster rightRaster = right.getData();
    int[] leftPixes = new int[4];
    int[] rightPixes = new int[4];

    for (int x = 0; x < right.getWidth(); x++) {
        for (int y = 0; y < right.getHeight(); y++) {
            leftPixes = leftRaster.getPixel(x, y, leftPixes);
            rightPixes = rightRaster.getPixel(x, y, rightPixes);

            for (int i = 0; i < leftRaster.getNumBands(); i++) {
                if (Math.abs(leftPixes[i] - rightPixes[i]) > DIFF_VALUE) {
                    if (!ignoreError) {
                        assertTrue(name + "'s pix not equal, sub is " + (leftPixes[i] - rightPixes[i]), false);
                    }
                }

                leftPixes[i] = 0;
                rightPixes[i] = 0;
            }
        }
    }
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a box plot qimage.//  w  w w .j  a  v  a2  s.c o  m
 * @param data Data to use
 * @return a QImage
 */
public QImage createBoxPlot(final double[] data, final String unit) {

    if (data == null || data.length < 2)
        return null;

    this.width = this.width / 2;

    List<Float> listData = new ArrayList<Float>(data.length);
    for (int i = 0; i < data.length; i++)
        listData.add((float) data[i]);

    DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset();
    defaultboxandwhiskercategorydataset.add(listData, "Distances", "Min");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "",
            "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false);

    addTransparency(chart);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);

}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a histogram of distance distribution.
 * @param results Result to use//from   ww  w . j  a v a2  s. c  o m
 * @return a QImage of the graph
 */
public QImage createDistanceDistributionImage(final CorsenResult results, final int classes,
        final String unit) {

    HistogramDataset histogramdataset = new HistogramDataset();

    createHistoDataSet(results.getMinDistances(), "Min distances", histogramdataset, classes);
    // createHistoDataSet(results.getMaxDistances(), "Max distances",
    // histogramdataset);

    JFreeChart chart = ChartFactory.createHistogram("Distribution of minimal distances",
            // title
            "Distance" + unitLegend(unit), // domain axis label
            "Intensity", // range axis label
            histogramdataset, // data

            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    addTransparency(chart);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

public QImage createDistanceDistributionImage(final double[] data, final int classes, final String unit) {

    if (data == null || data.length < 2)
        return null;

    HistogramDataset histogramdataset = new HistogramDataset();

    histogramdataset.addSeries("Min distances", data, classes, getMin(data), getMax(data));

    // createHistoDataSet(results.getMaxDistances(), "Max distances",
    // histogramdataset);

    JFreeChart chart = ChartFactory.createHistogram("Distribution of minimal distances",
            // title
            "Distance" + unitLegend(unit), // domain axis label
            "Cell number", // range axis label
            histogramdataset, // data

            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );// ww w.j av a  2 s  .  c  o  m

    addTransparency(chart);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a scatter plot/*from   ww w  . ja  va2  s  .  co  m*/
 * @param particles Particle data to use
 * @param title Title of the graph
 * @return a QImage
 */
public QImage createScatterPlot(final Particles3D particles, final String title, final String unit) {

    if (particles == null)
        return null;

    List<Particle3D> pars = particles.getParticles();

    final int count = pars.size();

    final double[][] data = new double[2][];
    data[0] = new double[count];
    data[1] = new double[count];

    int i = 0;
    for (Particle3D p : pars) {

        data[0][i] = p.getIntensity();
        data[1][i] = p.getVolume();
        i++;
    }

    DefaultXYDataset xydataset = new DefaultXYDataset();
    xydataset.addSeries("data", data);

    JFreeChart chart = ChartFactory.createScatterPlot(title, "Intensity", "Volume" + unitLegendCude(unit),
            xydataset, PlotOrientation.VERTICAL, false, true, false);

    addTransparency(chart);

    XYPlot xyplot = (XYPlot) chart.getPlot();
    XYDotRenderer xydotrenderer = new XYDotRenderer();
    xydotrenderer.setDotWidth(2);
    xydotrenderer.setDotHeight(2);
    xyplot.setRenderer(xydotrenderer);
    NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis();
    numberaxis.setAutoRangeIncludesZero(false);

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:org.xlrnet.tibaija.tools.fontgen.FontgenApplication.java

private Symbol importFile(Path path, Font font, String fontIdentifier) throws IOException, ImageReadException {
    LOGGER.info("Importing file {} ...", path.toAbsolutePath());

    BufferedImage image = Imaging.getBufferedImage(Files.newInputStream(path));
    int width = image.getWidth();
    int height = image.getHeight();
    int finalWidth = width / 2;
    int finalHeight = height / 2;

    if (width % 2 != 0 || height % 2 != 0) {
        LOGGER.warn("Width and height must be multiple of 2");
        return null;
    }//from   w w w  . j a va  2s. c  o m

    Symbol symbol = new Symbol();
    PixelState[][] pixelStates = new PixelState[finalHeight][finalWidth];
    Raster imageData = image.getData();

    for (int y = 0; y < finalHeight; y++) {
        for (int x = 0; x < finalWidth; x++) {
            int sample = imageData.getSample(x * 2, y * 2, 0);
            PixelState pixelState = sample == 0 ? PixelState.ON : PixelState.OFF;
            pixelStates[y][x] = pixelState;
        }
    }

    symbol.setData(pixelStates);
    return symbol;
}

From source file:fr.ens.transcriptome.corsen.gui.qt.ResultGraphs.java

/**
 * Create a boxplot./*from ww  w .  ja v  a 2 s. com*/
 * @param results Results to use
 * @return a QImage
 */
public QImage createBoxPlot(final CorsenResult results, final String unit) {

    this.width = this.width / 2;

    Map<Particle3D, Distance> distsMin = results.getMinDistances();
    Map<Particle3D, Distance> distsMax = results.getMaxDistances();

    if (distsMin == null || distsMax == null)
        return null;

    List<Float> listMin = new ArrayList<Float>();
    List<Float> listMax = new ArrayList<Float>();

    for (Map.Entry<Particle3D, Distance> e : distsMin.entrySet()) {

        final Particle3D p = e.getKey();

        final long intensity = p.getIntensity();
        final float distanceMin = e.getValue().getDistance();
        final float distanceMax = distsMax.get(p).getDistance();

        for (int i = 0; i < intensity; i++) {
            listMin.add(distanceMin);
            listMax.add(distanceMax);
        }
    }

    DefaultBoxAndWhiskerCategoryDataset defaultboxandwhiskercategorydataset = new DefaultBoxAndWhiskerCategoryDataset();

    if (results.getMinAnalyser().count() > 0)
        defaultboxandwhiskercategorydataset
                .add(convertDistanceAnalyserToBoxAndWhiskerItem(results.getMinAnalyser()), "Distances", "Min");

    // defaultboxandwhiskercategorydataset.add(listMin, "Distances", "Min");
    // defaultboxandwhiskercategorydataset.add(listMax, "Distances", "Max");

    JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Intensities Boxplot", "",
            "Distance" + unitLegend(unit), defaultboxandwhiskercategorydataset, false);

    addTransparency(chart);

    // CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    // // chart.setBackgroundPaint(Color.white);
    // categoryplot.setBackgroundPaint(Color.lightGray);
    // categoryplot.setDomainGridlinePaint(Color.white);
    // categoryplot.setDomainGridlinesVisible(true);
    // categoryplot.setRangeGridlinePaint(Color.white);
    //
    // NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    // numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final BufferedImage image = chart.createBufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB,
            null);

    return new QImage(toByte(image.getData().getDataBuffer()), this.width, this.height,
            QImage.Format.Format_ARGB32);
}

From source file:net.mindengine.oculus.frontend.web.controllers.project.ProjectEditController.java

private String saveProjectIconFromBufferedImage(BufferedImage image, Long id) throws IOException {
    Date date = new Date();
    String path = config.getDataFolder() + File.separator + "projects" + File.separator + id;
    new File(path).mkdirs();
    File file = new File(path + File.separator + "icon_" + date.getTime() + ".png");
    file.createNewFile();/*from   w  ww.j a v a  2 s .  c  om*/

    BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    imageRGB.setData(image.getData());

    ImageIO.write(imageRGB, "png", file);

    return Long.toString(date.getTime());
}