List of usage examples for java.awt.image ImageObserver ABORT
int ABORT
To view the source code for java.awt.image ImageObserver ABORT.
Click Source Link
From source file:Main.java
/** * Decodes the bits of a java.awt.image.ImageObserver infoflag into a human * readable string./*from w ww . j a va 2 s . co m*/ * * @param infoflag * the flag to decode * @return a string describing the flag */ public static String imageObserverInfoflagToString(int infoflag) { String out = ""; if ((infoflag & ImageObserver.ABORT) == ImageObserver.ABORT) out += "ABORT "; if ((infoflag & ImageObserver.ALLBITS) == ImageObserver.ALLBITS) out += "ALLBITS "; if ((infoflag & ImageObserver.ERROR) == ImageObserver.ERROR) out += "ERROR "; if ((infoflag & ImageObserver.FRAMEBITS) == ImageObserver.FRAMEBITS) out += "FRAMEBITS "; if ((infoflag & ImageObserver.HEIGHT) == ImageObserver.HEIGHT) out += "HEIGHT "; if ((infoflag & ImageObserver.PROPERTIES) == ImageObserver.PROPERTIES) out += "PROPERTIES "; if ((infoflag & ImageObserver.SOMEBITS) == ImageObserver.SOMEBITS) out += "SOMEBITS "; if ((infoflag & ImageObserver.WIDTH) == ImageObserver.WIDTH) out += "WIDTH "; return out; }
From source file:Util.java
/** * Converts a java.awt.Image into an array of pixels *//*from w w w . j ava 2 s. c o m*/ public static int[] convertToPixels(Image img) { int width = img.getWidth(null); int height = img.getHeight(null); int[] pixel = new int[width * height]; PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height, pixel, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { throw new IllegalStateException("Error: Interrupted Waiting for Pixels"); } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { throw new IllegalStateException("Error: Image Fetch Aborted"); } return pixel; }
From source file:ImageUtilities.java
/** * Starts loading the given image, returns only when it's done loading. * Note that it's much more efficient to preload a lot of images at once using * the preload(Image []) method instead of this one. * * @return The result of the image loading, either {@link #COMPLETE}, * {@link #ERRORED}, {@link #ABORTED} or {@link #INTERRUPTED}. * * @see #preload(java.awt.Image [], int []) *//*from www . j av a 2s . com*/ public static int preload(Image image) { Toolkit toolkit = Toolkit.getDefaultToolkit(); // Check if already loaded if ((toolkit.checkImage(image, -1, -1, null) & ImageObserver.ALLBITS) != 0) return COMPLETE; Object lock = new Object(); synchronized (lock) { while (true) { ImageLoadObserver observer = new ImageLoadObserver(lock); toolkit.prepareImage(image, -1, -1, observer); int result = toolkit.checkImage(image, -1, -1, null); if ((result & ImageObserver.ALLBITS) != 0) return COMPLETE; if ((result & ImageObserver.ERROR) != 0) return ERRORED; if ((result & ImageObserver.ABORT) != 0) return ABORTED; try { lock.wait(); return observer.getResult(); } catch (InterruptedException e) { return INTERRUPTED; } } } }
From source file:ImageLoaderApplet.java
/** * Verbose version of ImageConsumer's imageUpdate method *///from w w w . j a v a 2s.com public boolean imageUpdate(Image img, int flags, int x, int y, int width, int height) { System.out.print("Flag(s): "); if ((flags & ImageObserver.WIDTH) != 0) { System.out.print("WIDTH:(" + width + ") "); } if ((flags & ImageObserver.HEIGHT) != 0) { System.out.print("HEIGHT:(" + height + ") "); } if ((flags & ImageObserver.PROPERTIES) != 0) { System.out.print("PROPERTIES "); } if ((flags & ImageObserver.SOMEBITS) != 0) { System.out.print("SOMEBITS(" + x + "," + y + ")->("); System.out.print(width + "," + height + ") "); repaint(); } if ((flags & ImageObserver.FRAMEBITS) != 0) { System.out.print("FRAMEBITS(" + x + "," + y + ")->("); System.out.print(width + "," + height + ") "); repaint(); } if ((flags & ImageObserver.ALLBITS) != 0) { System.out.print("ALLBITS(" + x + "," + y + ")->("); System.out.println(width + "," + height + ") "); repaint(); return false; } if ((flags & ImageObserver.ABORT) != 0) { System.out.println("ABORT \n"); return false; } if ((flags & ImageObserver.ERROR) != 0) { System.out.println("ERROR "); return false; } System.out.println(); return true; }
From source file:com.jcraft.weirdx.TransparentFilter.java
TransparentFilter(int cx, int cy, XPixmap pixmap) { this.cx = cx; this.cy = cy; this.width = pixmap.width; this.height = pixmap.height; pixels = new byte[pixmap.width * pixmap.height]; if (pixmap.data != null) { for (int i = 0; i < pixmap.height; i++) { for (int j = 0; j < pixmap.width; j++) { if (pixmap.data[i * pixmap.width + j] == 0) { pixels[i * pixmap.width + j] = 0; } else { pixels[i * pixmap.width + j] = 1; }//from w w w. ja v a 2 s . co m } } } else { int[] ipixels = new int[pixmap.width * pixmap.height]; Image img = pixmap.img; PixelGrabber pg = null; pg = new PixelGrabber(img, 0, 0, pixmap.width, pixmap.height, ipixels, 0, pixmap.width); try { pg.grabPixels(); } catch (InterruptedException e) { //System.err.println("interrupted waiting for pixels!"); return; } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { LOG.error("image fetch aborted or errored"); return; } for (int i = 0; i < pixmap.height; i++) { for (int j = 0; j < pixmap.width; j++) { if (ipixels[i * pixmap.width + j] == 0xff000000) { pixels[i * pixmap.width + j] = 0; } else { pixels[i * pixmap.width + j] = 1; } } } ipixels = null; } }
From source file:ImageUtilities.java
/** * Starts loading the given images, returns only when all the images are done * loading. If you just need to preload one Image, use the preload(Image) method * instead.//w w w . jav a 2 s .c o m * * @return An array specifying the loading result of each image. Possible values * are {@link #COMPLETE}, {@link #ERRORED} and {@link #ABORTED}. * * @see #preload(Image) */ public static int[] preload(Image[] images, int[] results) { Object[] locks = new Object[images.length]; ImageLoadObserver[] loadObservers = new ImageLoadObserver[images.length]; if ((results == null) || (results.length < images.length)) results = new int[images.length]; Toolkit toolkit = Toolkit.getDefaultToolkit(); for (int i = 0; i < images.length; i++) { locks[i] = new Object(); loadObservers[i] = new ImageLoadObserver(locks[i]); toolkit.prepareImage(images[i], -1, -1, loadObservers[i]); } for (int i = 0; i < images.length; i++) { synchronized (locks[i]) { int result = toolkit.checkImage(images[i], -1, -1, null); if ((result & ImageObserver.ALLBITS) != 0) { results[i] = COMPLETE; continue; } if ((result & ImageObserver.ERROR) != 0) { results[i] = ERRORED; continue; } if ((result & ImageObserver.ABORT) != 0) { results[i] = ABORTED; continue; } try { locks[i].wait(); results[i] = loadObservers[i].getResult(); } catch (InterruptedException e) { results[i] = INTERRUPTED; } } } return results; }
From source file:WaitingImageObserver.java
/** * Callback function used by AWT to inform that more data is available. The * observer waits until either all data is loaded or AWT signals that the * image cannot be loaded./*from w w w .j a v a2 s . c o m*/ * * @param img the image being observed. * @param infoflags the bitwise inclusive OR of the following * flags: <code>WIDTH</code>, <code>HEIGHT</code>, * <code>PROPERTIES</code>, <code>SOMEBITS</code>, * <code>FRAMEBITS</code>, <code>ALLBITS</code>, * <code>ERROR</code>, <code>ABORT</code>. * @param x the <i>x</i> coordinate. * @param y the <i>y</i> coordinate. * @param width the width. * @param height the height. * * @return <code>false</code> if the infoflags indicate that the * image is completely loaded; <code>true</code> otherwise. */ public synchronized boolean imageUpdate(final Image img, final int infoflags, final int x, final int y, final int width, final int height) { if ((infoflags & ImageObserver.ALLBITS) == ImageObserver.ALLBITS) { this.lock = false; this.error = false; notifyAll(); return false; } else if ((infoflags & ImageObserver.ABORT) == ImageObserver.ABORT || (infoflags & ImageObserver.ERROR) == ImageObserver.ERROR) { this.lock = false; this.error = true; notifyAll(); return false; } //notifyAll(); return true; }
From source file:com.t3.image.ImageUtil.java
/** * Look at the image and determine which Transparency is most appropriate. * If it finds any translucent pixels it returns Transparency.TRANSLUCENT, if * it finds at least one purely transparent pixel and no translucent pixels * it will return Transparency.BITMASK, in all other cases it returns * Transparency.OPAQUE, including errors * //from w w w .jav a2 s . co m * @param image * @return one of Transparency constants */ public static int pickBestTransparency(Image image) { // Take a shortcut if possible if (image instanceof BufferedImage) { return pickBestTransparency((BufferedImage) image); } // Legacy method // NOTE: This is a horrible memory hog int width = image.getWidth(null); int height = image.getHeight(null); int[] pixelArray = new int[width * height]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixelArray, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return Transparency.OPAQUE; } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); return Transparency.OPAQUE; } // Look for specific pixels boolean foundTransparent = false; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Get the next pixel int pixel = pixelArray[y * width + x]; int alpha = (pixel >> 24) & 0xff; // Is there translucency or just pure transparency ? if (alpha > 0 && alpha < 255) { return Transparency.TRANSLUCENT; } if (alpha == 0 && !foundTransparent) { foundTransparent = true; } } } return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE; }
From source file:net.rptools.lib.image.ImageUtil.java
/** * Look at the image and determine which Transparency is most appropriate. If it finds any translucent pixels it * returns Transparency.TRANSLUCENT, if it finds at least one purely transparent pixel and no translucent pixels it * will return Transparency.BITMASK, in all other cases it returns Transparency.OPAQUE, including errors * //from w w w .jav a 2 s. c o m * @param image * @return one of Transparency constants */ public static int pickBestTransparency(Image image) { // Take a shortcut if possible if (image instanceof BufferedImage) { return pickBestTransparency((BufferedImage) image); } // Legacy method // NOTE: This is a horrible memory hog int width = image.getWidth(null); int height = image.getHeight(null); int[] pixelArray = new int[width * height]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixelArray, 0, width); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return Transparency.OPAQUE; } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { System.err.println("image fetch aborted or errored"); return Transparency.OPAQUE; } // Look for specific pixels boolean foundTransparent = false; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { // Get the next pixel int pixel = pixelArray[y * width + x]; int alpha = (pixel >> 24) & 0xff; // Is there translucency or just pure transparency ? if (alpha > 0 && alpha < 255) { return Transparency.TRANSLUCENT; } if (alpha == 0 && !foundTransparent) { foundTransparent = true; } } } return foundTransparent ? Transparency.BITMASK : Transparency.OPAQUE; }
From source file:com.jcraft.weirdx.XPixmap.java
void image2data(int x, int y, int w, int h) { if (pixels.length < w * h) { pixels = new int[w * h]; }//from www . j a v a 2s .c o m PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); try { pg.grabPixels(); } catch (InterruptedException e) { LOG.error("interrupted waiting for pixels!"); return; } if ((pg.getStatus() & ImageObserver.ABORT) != 0) { LOG.error("image fetch aborted or errored"); return; } byte[] dt = getData(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { dt[(y + i) * width + x + j] = (byte) colormap.rgb2pixel(pixels[i * w + j]); } } time = 0; }