Refine search
bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { type = BufferedImage.TYPE_INT_ARGB; bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); Graphics g = bimage.createGraphics(); return bimage.getColorModel().hasAlpha(); PixelGrabber pg = new PixelGrabber(image, 0, 0, 1, 1, false); try { pg.grabPixels(); } catch (InterruptedException e) { ColorModel cm = pg.getColorModel(); return cm.hasAlpha();
pg = new PixelGrabber(this.image, 0, startRow, this.width, nRows, pixels, 0, this.width); try { pg.grabPixels(); return false; if ((pg.getStatus() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); return false;
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]; }
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; }
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]); // ... String sUrl="http://img01.taobaocdn.com/imgextra/i1/449400070/T2hbVwXj0XXXXXXXXX_!!449400070.jpg"; URL url = new URL(sUrl); Image img = Toolkit.getDefaultToolkit().createImage(url); PixelGrabber pg = new PixelGrabber(img, 0, 0, -1, -1, true); pg.grabPixels(); 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); String to = "D:/temp/result.jpg"; ImageIO.write(bi, "jpg", new File(to));
for (int j = 0; j < maxJ; j++) { final BufferedImage bufferedImage = capture.getSubimage(i * tileWidth, j * tileWidth, tileWidth, tileWidth); PixelGrabber pg = new PixelGrabber(bufferedImage, 0, 0, tileWidth, tileWidth, pixels, 0, tileWidth); if (pg.grabPixels()) {
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; }
/** * 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; }
public static int[] rasterize(BufferedImage img) { int[] pixels = new int[img.getWidth() * img.getHeight()]; PixelGrabber grabber = new PixelGrabber(img, 0, 0, img.getWidth(), img.getHeight(), pixels, 0, img.getWidth()); try { grabber.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); } return pixels; }
public static BufferedImage toBufferedImage(final Image image) throws InterruptedException { if (image instanceof BufferedImage) return (BufferedImage) image; MediaTracker tracker = new MediaTracker(new Component() { }); tracker.addImage(image, 0); tracker.waitForAll(); PixelGrabber pixelGrabber = new PixelGrabber(image, 0, 0, -1, -1, false); pixelGrabber.grabPixels(); ColorModel cm = pixelGrabber.getColorModel(); final int w = pixelGrabber.getWidth(); final int h = pixelGrabber.getHeight(); WritableRaster raster = cm.createCompatibleWritableRaster(w, h); final BufferedImage renderedImage = new BufferedImage(cm, raster, cm .isAlphaPremultiplied(), new Hashtable()); renderedImage.getRaster().setDataElements(0, 0, w, h, pixelGrabber.getPixels()); return renderedImage; } }
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(); }
protected int[][] grabPixels(final Image image) { final int width = image.getWidth(null); final int lines = image.getHeight(null); final int pixels[] = new int[width * lines]; final PixelGrabber grabber = new PixelGrabber(image, 0, 0, width, lines, pixels, 0, width); grabber.setColorModel(ColorModel.getRGBdefault()); try { if (grabber.grabPixels() && (grabber.status() & ImageObserver.ALLBITS) != 0) { final int[][] array = new int[lines][width]; int srcPos = 0; for (int line = 0; line < lines; line++) { array[line] = new int[width]; System.arraycopy(pixels, srcPos, array[line], 0, width); for (int pixel = 0; pixel < array[line].length; pixel++) { array[line][pixel] = array[line][pixel] | 0xFF000000; } srcPos += width; } return array; } // TODO what happens if the grab fails? return new int[lines][width]; } catch (final InterruptedException e) { throw new IsisException(e); } }
private static Color getGTKProfilerResultsBackground() { int[] pixels = new int[1]; pixels[0] = -1; // Prepare textarea to grab the color from JTextArea textArea = new JTextArea(); textArea.setSize(new Dimension(10, 10)); textArea.doLayout(); // Print the textarea to an image Image image = new BufferedImage(textArea.getSize().width, textArea.getSize().height, BufferedImage.TYPE_INT_RGB); textArea.printAll(image.getGraphics()); // Grab appropriate pixels to get the color PixelGrabber pixelGrabber = new PixelGrabber(image, 5, 5, 1, 1, pixels, 0, 1); try { pixelGrabber.grabPixels(); if (pixels[0] == -1) return Color.WHITE; // System background not customized } catch (InterruptedException e) { return getNonGTKProfilerResultsBackground(); } return pixels[0] != -1 ? new Color(pixels[0]) : getNonGTKProfilerResultsBackground(); }
public static int[] getImageIntPixels(Image image, int x, int y, int width, int height, boolean allowDeoptimizingDirectRead) { if (image instanceof BufferedImage) { BufferedImage bim = (BufferedImage)image; WritableRaster raster = bim.getRaster(); if (allowDeoptimizingDirectRead && raster.getParent() == null && raster.getDataBuffer().getNumBanks() == 1) { DataBuffer b = bim.getRaster().getDataBuffer(); if (b instanceof DataBufferInt) { int[] array = ((DataBufferInt)b).getData(); 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 boolean isValid(String imageUrl) throws IOException, InterruptedException { URL url = new URL(imageUrl); Image img = ImageIO.read(url); //img = img.getScaledInstance(100, -1, Image.SCALE_FAST); int w = img.getWidth(null); int h = img.getHeight(null); int[] pixels = new int[w * h]; PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixels, 0, w); pg.grabPixels(); boolean isValid = false; for (int pixel : pixels) { Color color = new Color(pixel); if (color.getAlpha() == 0 || color.getRGB() != Color.WHITE.getRGB()) { isValid = true; break; } } return isValid; }
/** Expects x,y in world coordinates. This method is intended for grabing an occasional pixel; to grab all pixels, see @getImageProcessor method. */ public int[] getPixel(final int x, final int y, final double mag) { if (project.getLoader().isUnloadable(this)) return new int[4]; final MipMapImage mipMap = project.getLoader().fetchImage(this, mag); if (Loader.isSignalImage(mipMap.image)) return new int[4]; final int w = mipMap.image.getWidth(null); final Point2D.Double pd = inverseTransformPoint(x, y); final int x2 = (int)(pd.x / mipMap.scaleX); final int y2 = (int)(pd.y / mipMap.scaleY); final int[] pvalue = new int[4]; final PixelGrabber pg = new PixelGrabber( mipMap.image, x2, y2, 1, 1, pvalue, 0, w); try { pg.grabPixels(); } catch (final InterruptedException ie) { return pvalue; } approximateTransferPixel(pvalue); return pvalue; }
protected void setPreferredBackground() { int[] pixels = new int[1]; PixelGrabber pg = null; switch (imageAlign) { case (SwingConstants.TOP): pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1); break; case (SwingConstants.BOTTOM): pg = new PixelGrabber(image, 0, 0, 1, 1, pixels, 0, 1); break; default: pg = new PixelGrabber(image, 0, image.getHeight(null) - 1, 1, 1, pixels, 0, 1); } try { if ((pg != null) && pg.grabPixels()) { setBackground(new Color(pixels[0])); } } catch (InterruptedException e) { } }
@Nullable public static Color getColorAt(final Icon icon, final int x, final int y) { if (0 <= x && x < icon.getIconWidth() && 0 <= y && y < icon.getIconHeight()) { final BufferedImage image = createImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); icon.paintIcon(null, image.getGraphics(), 0, 0); final int[] pixels = new int[1]; final PixelGrabber pixelGrabber = new PixelGrabber(image, x, y, 1, 1, pixels, 0, 1); try { pixelGrabber.grabPixels(); return new Color(pixels[0]); } catch (InterruptedException ignored) { } } return null; }
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); }
java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage, 0, 0, -1, -1, true); try { pg.grabPixels(); } catch (InterruptedException e) { throw new IOException( "java.awt.Image Interrupted waiting for pixels!"); if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { throw new IOException("java.awt.Image fetch aborted or errored"); int w = pg.getWidth(); int h = pg.getHeight(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2d = tp.createGraphics(w, h, true, quality);