Java 8 PixelGrabber - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PixelGrabber class.

This code example shows how to use the following methods:getHeight, getPixels, getWidth, grabPixels, status
 	public ImageFunction2D(Image image) {
		this( image, ZERO, false );
 	} 
	 
	public ImageFunction2D(Image image, int edgeAction, boolean alpha) {
 		PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, null, 0, -1);
 		try { 
 			pg.grabPixels();
 		} catch (InterruptedException e) {
 			throw new RuntimeException("interrupted waiting for pixels!");
 		} 
 		if ((pg.status() & ImageObserver.ABORT) != 0) {
 			throw new RuntimeException("image fetch aborted");
 		} 
 		init((int[])pg.getPixels(), pg.getWidth(), pg.getHeight(), edgeAction, alpha);
  	} 
 
	/** 
	 * A convenience method for getting ARGB pixels from an image. This tries to avoid the performance 
	 * penalty of BufferedImage.getRGB unmanaging the image. 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getHeight, getPixels, getWidth, grabPixels, status
     * Cretae a BufferedImage from an ImageProducer. 
     * @param producer the ImageProducer 
     * @return a new TYPE_INT_ARGB BufferedImage 
     */ 
    public static BufferedImage createImage(ImageProducer producer) {
		PixelGrabber pg = new PixelGrabber(producer, 0, 0, -1, -1, null, 0, 0);
		try { 
			pg.grabPixels();
		} catch (InterruptedException e) {
			throw new RuntimeException("Image fetch interrupted");
		} 
		if ((pg.status() & ImageObserver.ABORT) != 0)
			throw new RuntimeException("Image fetch aborted");
		if ((pg.status() & ImageObserver.ERROR) != 0)
			throw new RuntimeException("Image fetch error");
		BufferedImage p = new BufferedImage(pg.getWidth(), pg.getHeight(), BufferedImage.TYPE_INT_ARGB);
		p.setRGB(0, 0, pg.getWidth(), pg.getHeight(), (int[])pg.getPixels(), 0, pg.getWidth());
		return p;
	} 
	 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPixels, grabPixels
					return array;
				} 
			} 
			return bim.getRGB(x, y, width, height, null, 0, width);
		} 
		PixelGrabber grabber = new PixelGrabber(image, x, y, width, height, true);
		try { 
			grabber.grabPixels();
			return (int[])grabber.getPixels();
		} catch (InterruptedException ex) {
			throw new RuntimeException("Pixel read operation was interrupted", ex);
		} 
	} 
 
	public static void setImageIntPixels(BufferedImage image, boolean allowDeoptimizingDirectRead, IntBuffer pixels) {
		setImageIntPixels(image, 0, 0, image.getWidth(null), image.getHeight(null), allowDeoptimizingDirectRead, pixels);
	} 
	public static void setImageIntPixels(BufferedImage bim, int x, int y, int width, int height, boolean allowDeoptimizingDirectRead, IntBuffer pixels) {
		WritableRaster raster = bim.getRaster();
		if (allowDeoptimizingDirectRead &&
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getStatus, grabPixels
      h = dimensionGetter.getHeight();
    } catch (Exception e) {
      throw new LoadingException("image missing or corrupted", e);
    } 
    int[] pixels = new int[w * h];
    PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
    try { 
      pixelGrabber.grabPixels();
    } catch (InterruptedException e) {
      throw new LoadingException("interrupted waiting for pixels!", e);
    } 
    if ((pixelGrabber.getStatus() & ImageObserver.ABORT) != 0) {
      throw new LoadingException("image fetch aborted or errored"); 
    } 
    MemoryImageSource memoryImageSource = new MemoryImageSource(w, h, pixels, 0, w);
    return Toolkit.getDefaultToolkit().createImage(memoryImageSource);
  } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:grabPixels
This code example shows how to use the following methods:getStatus, grabPixels
        if (image == null) {
            out.writeObject(null);
        } else { 
            int[] pixels = new int[width * height];
            try { 
                PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
                pg.grabPixels();
                if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                    throw new IOException("Unable to serialize java.awt.image: PixelGrabber aborted.");
                } 
            } catch (InterruptedException ex) {
                throw new IOException("Unable to serialize java.awt.Image: PixelGrabber interrupted.");
            } 
            out.writeObject(pixels);
        } 
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getColorModel, grabPixels
            BufferedImage bimage = (BufferedImage)image;
            return bimage.getColorModel().hasAlpha();
        } 
        // Use a pixel grabber to retrieve the image's color model; 
        // grabbing a single pixel is usually sufficient 
        PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
        try { 
            pg.grabPixels();
        } catch (InterruptedException e) {
        	throw new ApsSystemException("Error grabbing a single pixel", e);
        } 
        // Get the image's color model 
        ColorModel cm = pg.getColorModel();
        return cm.hasAlpha();
	} 
	 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getColorModel, grabPixels
			return ((BufferedImage) image).getColorModel().hasAlpha();
		} 
 
		// Use a pixel grabber to retrieve the image's color model; 
		// grabbing a single pixel is usually sufficient 
		PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
		try { 
			pg.grabPixels();
		} catch (InterruptedException e) {
		} 
 
		// Get the image's color model 
		return pg.getColorModel().hasAlpha();
	} 
 
	/** 
	 * Code from http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html 
	 * @param img 
	 * @param targetWidth 
	 * @param targetHeight 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:grabPixels
    int height = getHeight();
    pixels = new int[width * height];
 
    // Seems best in this situation to grab all pixels upfront. Grabbing any individual pixel 
    // entails creating a relatively expensive object and calling through several methods. 
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width);
    try { 
      grabber.grabPixels();
    } catch (InterruptedException ie) {
      throw ReaderException.getInstance(); 
    } 
  } 
 
  public byte[] getRow(int y, byte[] row) {
    if (y < 0 || y >= getHeight()) {
      throw new IllegalArgumentException("Requested row is outside the image: " + y);
    } 
    int width = getWidth();
    if (row == null || row.length < width) {
      row = new byte[width];
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getColorModel, grabPixels
	} 
 
	public static boolean hasAlpha(Image image) throws InterruptedException {
		if (image instanceof BufferedImage)
			return ((BufferedImage) image).getColorModel().hasAlpha();
		PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false);
		pg.grabPixels();
		return pg.getColorModel().hasAlpha();
	} 
 
	public static void checkPlugins() { 
		ImageIO.scanForPlugins();
		if (Logging.isDebug) 
			for (String suffix : ImageIO.getReaderFileSuffixes())
				Logging.debug("ImageIO suffix: " + suffix);
	} 
 
	public static ImageReader findImageReader(String formatName) {
		Iterator<ImageReader> readers = ImageIO
				.getImageReadersByFormatName(formatName);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 PixelGrabber Methods: