Example usage for org.apache.commons.imaging Imaging getBufferedImage

List of usage examples for org.apache.commons.imaging Imaging getBufferedImage

Introduction

In this page you can find the example usage for org.apache.commons.imaging Imaging getBufferedImage.

Prototype

public static BufferedImage getBufferedImage(final File file) throws ImageReadException, IOException 

Source Link

Document

Reads the first image from a file.

Usage

From source file:tachyon.view.Viewer.java

public static BufferedImage imageReadExample(final File file) throws ImageReadException, IOException {
    final BufferedImage image = Imaging.getBufferedImage(file);
    return image;
}

From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java

/**
 * Load an image /*from   w ww  .  j av  a2 s . co  m*/
 * @param pImage image to load
 * @return loaded image
 */
private BufferedImage internalLoadImage(File pImage) {
    try {
        if (pImage.getName().toLowerCase().endsWith(".jp2")) {
            //load a jp2?
            //FIXME: use openjpeg?
            //this uses jai (jj2000)
            //BufferedImage image = ImageIO.read(pImage);
            BufferedImage image = null;//OpenJPEGLoader.loadJP2(pImage);
            return image;
        }
        return Imaging.getBufferedImage(pImage);
    } catch (IOException e) {
        return null;
    } catch (NullPointerException e) {
        return null;
    } catch (ImageReadException e) {
        return null;
    }
}

From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java

/**
 * overlay heatmap on image/*w  ww.ja  v  a2s .  co  m*/
 */
private void internalOverlayHeatmap() {

    gRightImageSave = imageRight.getImage();

    if (!gHeatmapGenerated) {

        internalBeforeGUIThread();

        //threaded load so GUI doesn't hang
        Task<Integer> task = new Task<Integer>() {

            @Override
            protected Integer call() throws Exception {
                BufferedImage image = SwingFXUtils.fromFXImage(imageRight.getImage(), null);

                if (gHeatmap == null) {
                    //re-generate heatmap (must be on a re-load)
                    try {
                        gHeatmap = Imaging.getBufferedImage(gResults.get(gCurrentRecord).getHeatmapTemp());
                    } catch (IOException | ImageReadException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                for (int y = 0; y < image.getHeight(); y++) {
                    for (int x = 0; x < image.getWidth(); x++) {
                        int rgb = image.getRGB(x, y);

                        Color heatmapColor = new Color(gHeatmap.getRGB((x / DissimilarV2.SSIMWINDOWSIZE),
                                (y / DissimilarV2.SSIMWINDOWSIZE)));
                        int heatmapPixel = heatmapColor.getGreen();//&maxPixelValue;
                        if (heatmapColor.getGreen() != heatmapColor.getBlue()
                                && heatmapColor.getBlue() != heatmapColor.getRed()) {
                            gLogger.error("Heatmap error (should not happen)");
                        }

                        double factor = 1 - (((double) heatmapPixel / 255));

                        Color col = new Color(rgb);
                        int red = (int) (factor * col.getRed());
                        int green = (int) (factor * col.getGreen());
                        int blue = (int) (factor * col.getBlue());

                        if (red < 0)
                            red = 0;
                        if (green < 0)
                            green = 0;
                        if (blue < 0)
                            blue = 0;
                        col = new Color(red, green, blue);

                        image.setRGB(x, y, col.getRGB());
                    }
                }

                gHeatmapImage = SwingFXUtils.toFXImage(image, null);
                gHeatmapGenerated = true;

                Platform.runLater(new Runnable() {
                    //@Override
                    public void run() {
                        imageRight.setImage(gHeatmapImage);
                    }
                });

                internalAfterGUIThread();

                return 1;
            }

        };

        progressIndicator.progressProperty().bind(task.progressProperty());
        Thread loader = new Thread(task);
        loader.setDaemon(true);
        loader.start();

    } else {
        imageRight.setImage(gHeatmapImage);
    }

}