public static int[] getPixels(BufferedImage image){ int iWidth = image.getWidth(); int iHeight = image.getHeight(); int numPixels = iWidth*iHeight; int rawPixels[] = new int[numPixels]; if (rawPixels==null) return null; PixelGrabber grabber = new PixelGrabber(image,0,0,iWidth,iHeight,rawPixels,0,iWidth); try{ grabber.grabPixels(); } catch (InterruptedException e){ //do nothing } return rawPixels; }
/** * Converts the buffered image into a sprite image and returns it * @param image The image to be converted * @param client Current client instance * @return The buffered image as a sprite image */ public static SpritePixels getImageSpritePixels(BufferedImage image, Client client) { int[] pixels = new int[image.getWidth() * image.getHeight()]; try { new PixelGrabber(image, 0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()) .grabPixels(); } catch (InterruptedException ex) { log.debug("PixelGrabber was interrupted: ", ex); } return client.createSpritePixels(pixels, image.getWidth(), image.getHeight()); } }
if (pg.grabPixels()) {
this.width, nRows, pixels, 0, this.width); try { pg.grabPixels();
pg.grabPixels(); } catch (InterruptedException e) {
DirectGif89Frame(Image img) throws IOException { PixelGrabber pg = new PixelGrabber(img, 0, 0, -1, -1, true); String errmsg = null; try { if (!pg.grabPixels()) { errmsg = "can't grab pixels from image"; } } catch (InterruptedException e) { errmsg = "interrupted grabbing pixels from image"; } if (errmsg != null) { throw new IOException(errmsg + " (" + getClass().getName() + ")"); } theWidth = pg.getWidth(); theHeight = pg.getHeight(); argbPixels = (int[]) pg.getPixels(); ciPixels = new byte[argbPixels.length]; }
private static final int[] RGB_MASKS = {0xFF0000, 0xFF00, 0xFF}; private static final ColorModel RGB_OPAQUE = new DirectColorModel(32, RGB_MASKS[0], RGB_MASKS[1], RGB_MASKS[2]); ... BufferedImage image = componentToImage(imagePanel, true); saveJPeg(image, "c:/saved.jpg"); private void saveJPeg(BufferedImage image, String name) { PixelGrabber pg = new PixelGrabber(image, 0, 0, -1, -1, true); try { pg.grabPixels(); } catch (InterruptedException ex) { ex.printStackTrace(); } int width = pg.getWidth(), height = pg.getHeight(); DataBuffer buffer = new DataBufferInt((int[]) pg.getPixels(), pg.getWidth() * pg.getHeight()); WritableRaster raster = Raster.createPackedRaster(buffer, width, height, width, RGB_MASKS, null); BufferedImage bi = new BufferedImage(RGB_OPAQUE, raster, false, null); try { ImageIO.write(bi, "jpg", new File(name)); } catch (IOException ex) { ex.printStackTrace(); } }
static public final int[] extractARGBIntArray( final Image img ) { final int[] pix = new int[img.getWidth(null) * img.getHeight(null)]; PixelGrabber pg = new PixelGrabber( img, 0, 0, img.getWidth(null), img.getHeight(null), pix, 0, img.getWidth(null) ); try { pg.grabPixels(); } catch (InterruptedException ie) {} return pix; }
private static int[] getPixelArray(Image img) { int width = img.getWidth(null); int height = img.getHeight(null); int[] pixels = new int[width * height]; PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, pixels, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { } return pixels; }
public Picture(Image image, int width, int height){ this.image = image; this.width = width; // Breite bestimmen this.height = height; // Hoehe bestimmen pixels = new int[width*height]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixels, 0, width); try { pg.grabPixels(); } catch (InterruptedException ex) {} xs_xoff = xs = (float)(width/2. + 0.5); ys_yoff = ys = (float)(height/2. + 0.5); }
protected ImageInfo getImageInfo(byte[] bytes, Collection<ICompilerProblem> problems) throws Exception { // TODO This gets the image and width of the image. // Need to remove this and come up with a way to get the dimensions // without reading the whole file/using AWT. // http://bugs.adobe.com/jira/browse/CMP-542 Image image = Toolkit.getDefaultToolkit().createImage(bytes); PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, true); pixelGrabber.grabPixels(); ImageInfo imageInfo = new ImageInfo(pixelGrabber); return imageInfo; }
protected ImageInfo getImageInfo(byte[] bytes, Collection<ICompilerProblem> problems) throws Exception { // TODO This gets the image and width of the image. // Need to remove this and come up with a way to get the dimensions // without reading the whole file/using AWT. // http://bugs.adobe.com/jira/browse/CMP-542 Image image = Toolkit.getDefaultToolkit().createImage(bytes); PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, true); pixelGrabber.grabPixels(); ImageInfo imageInfo = new ImageInfo(pixelGrabber); return imageInfo; }
/** Returns the array of pixels, whose type depends on the bi.getType(); for example, for a BufferedImage.TYPE_BYTE_INDEXED, returns a byte[]. */ static public final Object grabPixels(final BufferedImage bi) { final PixelGrabber pg = new PixelGrabber(bi, 0, 0, bi.getWidth(), bi.getHeight(), false); try { pg.grabPixels(); return pg.getPixels(); } catch (InterruptedException e) { IJError.print(e); } return null; }
Image img = Toolkit.getDefaultToolkit().createImage(filename); PixelGrabber pg = new PixelGrabber(img, 0, 0, -1, -1, false); pg.grabPixels(); // Throws InterruptedException width = pg.getWidth(); height = pg.getHeight(); int[] pixels = (int[])pg.getPixels();
public static Image grab(Image image, int x, int y, int width, int height) { if (width * height < 0) return null; int[] pixels = new int[width * height]; PixelGrabber grabber = new PixelGrabber(image, x, y, width, height, pixels, 0, width); try { grabber.grabPixels(); } catch (Exception e) { e.printStackTrace(); } return bitmapCreator.createImage(new MemoryImageSource(width, height, pixels, 0, width)); }
/** Constructs a LookUpTable object from an AWT Image. */ public LookUpTable(Image img) { PixelGrabber pg = new PixelGrabber(img, 0, 0, 1, 1, false); try { pg.grabPixels(); cm = pg.getColorModel(); } catch (InterruptedException e){}; getColors(cm); }
private static boolean hasAlpha(Image image) { if (image instanceof BufferedImage) return ((BufferedImage) image).getColorModel().hasAlpha(); PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { } return pg.getColorModel().hasAlpha(); }
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); }
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); }
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); }