Java Code Examples for java.awt.image.BufferedImage#getData()

The following examples show how to use java.awt.image.BufferedImage#getData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShortHistogramTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
Example 2
Source File: ShortHistogramTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
Example 3
Source File: ShortHistogramTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
Example 4
Source File: ShortHistogramTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
Example 5
Source File: ShortHistogramTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
Example 6
Source File: ImageLoader.java    From Canova with Apache License 2.0 5 votes vote down vote up
public int[][] fromFile(File file) throws IOException {
    BufferedImage image = ImageIO.read(file);
    if (height > 0 && width > 0)
        image = toBufferedImage(image.getScaledInstance(height, width, Image.SCALE_SMOOTH));
    Raster raster = image.getData();
    int w = raster.getWidth(), h = raster.getHeight();
    int[][] ret = new int[w][h];
    for (int i = 0; i < w; i++)
        for (int j = 0; j < h; j++)
            ret[i][j] = raster.getSample(i, j, 0);

    return ret;
}
 
Example 7
Source File: ImgUtils.java    From mvisc with GNU General Public License v3.0 5 votes vote down vote up
public static Image getImageFromArray(int[] pixels, int width, int height) {
    BufferedImage image = new BufferedImage(width, height+1, BufferedImage.TYPE_INT_ARGB);
    WritableRaster raster = (WritableRaster) image.getData();
    System.out.println("px;" + pixels.length + " as opposed to " + (height*width));
    raster.setPixels(0,0,width,height-1,pixels);
    
    return image;
}
 
Example 8
Source File: FuzzyImageDifferenceCalculator.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
protected int getAverageBrightness( final BufferedImage img ) {
	final Raster r = img.getData();
	int total = 0;
	for ( int y = 0; y < r.getHeight(); y++ ) {
		for ( int x = 0; x < r.getWidth(); x++ ) {
			total += r.getSample( r.getMinX() + x, r.getMinY() + y, 0 );
		}
	}
	return (int) (total / (r.getWidth() / STABILIZER * (r.getHeight() / STABILIZER)));
}
 
Example 9
Source File: BMPImageReader.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 10
Source File: WBMPImageReader.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 11
Source File: WBMPImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 12
Source File: BMPImageReader.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 13
Source File: WBMPImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 14
Source File: BMPImageReader.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 15
Source File: BMPImageReader.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 16
Source File: BMPImageReader.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 17
Source File: BMPImageReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 18
Source File: CrashNaNTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testPathClosed() {
    final int width = 100;
    final int height = 100;

    final BufferedImage image = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = (Graphics2D) image.getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setBackground(Color.WHITE);
        g2d.clearRect(0, 0, width, height);

        final Path2D.Double path = new Path2D.Double();
        path.moveTo(40, 40);
        path.lineTo(0,   0);
        path.lineTo(80, 0);
        path.closePath();
        path.lineTo(80, 80);
        path.lineTo(0, 80);
        path.closePath();

        g2d.setColor(Color.BLUE);
        g2d.fill(path);

        g2d.setColor(Color.BLACK);
        g2d.draw(path);

        if (SAVE_IMAGE) {
            try {
                final File file = new File("CrashNaNTest-path-closed.png");
                System.out.println("Writing file: "
                                   + file.getAbsolutePath());
                ImageIO.write(image, "PNG", file);
            } catch (IOException ex) {
                System.out.println("Writing file failure:");
                ex.printStackTrace();
            }
        }

        // Check image on few pixels:
        final Raster raster = image.getData();

        checkPixel(raster, 10, 05, Color.BLUE.getRGB());
        checkPixel(raster, 70, 05, Color.BLUE.getRGB());
        checkPixel(raster, 40, 35, Color.BLUE.getRGB());

        checkPixel(raster, 10, 75, Color.BLUE.getRGB());
        checkPixel(raster, 70, 75, Color.BLUE.getRGB());
        checkPixel(raster, 40, 45, Color.BLUE.getRGB());

    } finally {
        g2d.dispose();
    }
}
 
Example 19
Source File: WBMPImageReader.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
Example 20
Source File: TruncatedFileException.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a <code>TruncatedFileException</code> with the
 * partially decoded BufferedImage.
 *
 * @param   bi the partially decoded BufferedImage (may be null).
 * @since   1.2
 */
public TruncatedFileException(BufferedImage bi) {
            super("Premature end of input file");
            this.bi  = bi;
            this.ras = bi.getData();
}