java.awt.image.ImageObserver Java Examples

The following examples show how to use java.awt.image.ImageObserver. 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: ImageRepresentation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public void setDimensions(int w, int h) {
    if (src != null) {
        src.checkSecurity(null, false);
    }

    image.setDimensions(w, h);

    newInfo(image, (ImageObserver.WIDTH | ImageObserver.HEIGHT),
            0, 0, w, h);

    if (w <= 0 || h <= 0) {
        imageComplete(ImageConsumer.IMAGEERROR);
        return;
    }

    if (width != w || height != h) {
        // dimension mismatch => trigger recreation of the buffer
        bimage = null;
    }

    width = w;
    height = h;

    availinfo |= ImageObserver.WIDTH | ImageObserver.HEIGHT;
}
 
Example #2
Source File: ImageRepresentation.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
synchronized void abort() {
    image.getSource().removeConsumer(this);
    consuming = false;
    newbits = null;
    bimage = null;
    biRaster = null;
    cmodel = null;
    srcLUT = null;
    isDefaultBI = false;
    isSameCM = false;

    newInfo(image, ImageObserver.ABORT, -1, -1, -1, -1);
    availinfo &= ~(ImageObserver.SOMEBITS
                   | ImageObserver.FRAMEBITS
                   | ImageObserver.ALLBITS
                   | ImageObserver.ERROR);
}
 
Example #3
Source File: SunGraphics2D.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private boolean scaleImage(Image img, int dx1, int dy1, int dx2, int dy2,
                           int sx1, int sy1, int sx2, int sy2,
                           Color bgcolor, ImageObserver observer)
{
    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example #4
Source File: DrawImage.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public boolean scaleImage(SunGraphics2D sg, Image img,
                            int x, int y,
                            int width, int height,
                            Color bgColor,
                            ImageObserver observer) {
    if (!(img instanceof ToolkitImage)) {
        return scaleImage(sg, img, x, y, width, height, bgColor);
    } else {
        ToolkitImage sunimg = (ToolkitImage)img;
        if (!imageReady(sunimg, observer)) {
            return false;
        }
        ImageRepresentation ir = sunimg.getImageRep();
        return ir.drawToBufImage(sg, sunimg, x, y, width, height, bgColor,
                                 observer);
    }
}
 
Example #5
Source File: ImageCombiner.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
    * Combines two images into one
    * 
    * @param image1
    *            left image
    * @param image2
    *            right image
    * @return combined Image
    */
   public static Image combine(ImageIcon image1, ImageIcon image2) {

ImageObserver comp = new JComponent() {
    private static final long serialVersionUID = 1L;
};

int w = image1.getIconWidth() + image2.getIconWidth();
int h = Math.max(image1.getIconHeight(), image2.getIconHeight());

BufferedImage image = new BufferedImage(w, h,
	BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = image.createGraphics();

g2.drawImage(image1.getImage(), 0, 0, comp);
g2.drawImage(image2.getImage(), image1.getIconWidth(), 0, comp);
g2.dispose();

return image;
   }
 
Example #6
Source File: ToolkitImage.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a property of the image by name.  Individual property names
 * are defined by the various image formats.  If a property is not
 * defined for a particular image, then this method will return the
 * UndefinedProperty object.  If the properties for this image are
 * not yet known, then this method will return null and the ImageObserver
 * object will be notified later.  The property name "comment" should
 * be used to store an optional comment which can be presented to
 * the user as a description of the image, its source, or its author.
 */
public Object getProperty(String name, ImageObserver observer) {
    if (name == null) {
        throw new NullPointerException("null property name is not allowed");
    }

    if (src != null) {
        src.checkSecurity(null, false);
    }
    if (properties == null) {
        addWatcher(observer, true);
        if (properties == null) {
            return null;
        }
    }
    Object o = properties.get(name);
    if (o == null) {
        o = Image.UndefinedProperty;
    }
    return o;
}
 
Example #7
Source File: ImageRepresentation.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public synchronized void reconstruct(int flags) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    int missinginfo = flags & ~availinfo;
    if ((availinfo & ImageObserver.ERROR) == 0 && missinginfo != 0) {
        numWaiters++;
        try {
            startProduction();
            missinginfo = flags & ~availinfo;
            while ((availinfo & ImageObserver.ERROR) == 0 &&
                   missinginfo != 0)
            {
                try {
                    wait();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    return;
                }
                missinginfo = flags & ~availinfo;
            }
        } finally {
            decrementWaiters();
        }
    }
}
 
Example #8
Source File: ValidatePipe.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean copyImage(SunGraphics2D sg, Image img,
                         int dx, int dy, int sx, int sy, int w, int h,
                         Color bgColor,
                         ImageObserver observer) {
    if (validate(sg)) {
        return sg.imagepipe.copyImage(sg, img, dx, dy, sx, sy, w, h,
                                      bgColor, observer);
    } else {
        return false;
    }
}
 
Example #9
Source File: ImageRepresentation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
synchronized void dispose() {
    image.getSource().removeConsumer(this);
    consuming = false;
    newbits = null;
    availinfo &= ~(ImageObserver.SOMEBITS
                   | ImageObserver.FRAMEBITS
                   | ImageObserver.ALLBITS);
}
 
Example #10
Source File: DrawImage.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public boolean copyImage(SunGraphics2D sg, Image img,
                         int x, int y,
                         Color bgColor,
                         ImageObserver observer) {
    if (!(img instanceof ToolkitImage)) {
        return copyImage(sg, img, x, y, bgColor);
    } else {
        ToolkitImage sunimg = (ToolkitImage)img;
        if (!imageReady(sunimg, observer)) {
            return false;
        }
        ImageRepresentation ir = sunimg.getImageRep();
        return ir.drawToBufImage(sg, sunimg, x, y, bgColor, observer);
    }
}
 
Example #11
Source File: SelectionGraphics.java    From megan-ce with GNU General Public License v3.0 5 votes vote down vote up
public boolean drawImage(Image image, int x, int y, int width, int height, ImageObserver imageObserver) {
    if (currentItem != null) {
        rectangle.setRect(x, y, width, height);
        testForHit(rectangle, false);
    }
    return true;
}
 
Example #12
Source File: ToolkitImage.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void addWatcher(ImageObserver iw, boolean load) {
    if ((availinfo & ImageObserver.ERROR) != 0) {
        if (iw != null) {
            iw.imageUpdate(this, ImageObserver.ERROR|ImageObserver.ABORT,
                           -1, -1, -1, -1);
        }
        return;
    }
    ImageRepresentation ir = getImageRep();
    ir.addWatcher(iw);
    if (load) {
        ir.startProduction();
    }
}
 
Example #13
Source File: ToolkitImage.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the width of the original image source.
 * If the width isn't known, then the image is reconstructed.
 */
public int getWidth() {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.WIDTH) == 0) {
        reconstruct(ImageObserver.WIDTH);
    }
    return width;
}
 
Example #14
Source File: ToolkitImage.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the width of the original image source.
 * If the width isn't known, then the image is reconstructed.
 */
public int getWidth() {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.WIDTH) == 0) {
        reconstruct(ImageObserver.WIDTH);
    }
    return width;
}
 
Example #15
Source File: ToolkitImage.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public int check(ImageObserver iw) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.ERROR) == 0 &&
        ((~availinfo) & (ImageObserver.WIDTH |
                         ImageObserver.HEIGHT |
                         ImageObserver.PROPERTIES)) != 0) {
        addWatcher(iw, false);
    }
    return availinfo;
}
 
Example #16
Source File: ValidatePipe.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean copyImage(SunGraphics2D sg, Image img,
                         int x, int y,
                         Color bgColor,
                         ImageObserver observer) {
    if (validate(sg)) {
        return sg.imagepipe.copyImage(sg, img, x, y, bgColor, observer);
    } else {
        return false;
    }
}
 
Example #17
Source File: ToolkitImage.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void preload(ImageObserver iw) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.ALLBITS) == 0) {
        addWatcher(iw, true);
    }
}
 
Example #18
Source File: ToolkitImage.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the width of the original image source.
 * If the width isn't known, then the ImageObserver object will be
 * notified when the data is available.
 */
public synchronized int getWidth(ImageObserver iw) {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.WIDTH) == 0) {
        addWatcher(iw, true);
        if ((availinfo & ImageObserver.WIDTH) == 0) {
            return -1;
        }
    }
    return width;
}
 
Example #19
Source File: ImageRepresentation.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public boolean drawToBufImage(Graphics g, ToolkitImage img,
                              int x, int y, Color bg,
                              ImageObserver iw) {

    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.ERROR) != 0) {
        if (iw != null) {
            iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
                           -1, -1, -1, -1);
        }
        return false;
    }
    boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
    boolean abort = ((availinfo & ImageObserver.ABORT) != 0);

    if (!done && !abort) {
        addWatcher(iw);
        startProduction();
        // Some producers deliver image data synchronously
        done = ((availinfo & ImageObserver.ALLBITS) != 0);
    }

    if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
        g.drawImage (bimage, x, y, bg, null);
    }

    return done;
}
 
Example #20
Source File: AbstractGraphics2D.java    From pumpernickel with MIT License 5 votes vote down vote up
/** Calls another <code>drawImage</code> method */
@Override
public boolean drawImage(Image i, int x, int y, Color bgColor,
		ImageObserver obs) {
	if (i instanceof BufferedImage) {
		BufferedImage bi = (BufferedImage) i;
		return drawImage(bi, x, y, x + bi.getWidth(), y + bi.getHeight(),
				bgColor, obs);
	}
	loadImage(i);
	return drawImage(i, x, y, x + i.getWidth(null), y + i.getHeight(null),
			bgColor, obs);
}
 
Example #21
Source File: ToolkitImage.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the height of the original image source.
 * If the height isn't known, then the image is reconstructed.
 */
public int getHeight() {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.HEIGHT) == 0) {
        reconstruct(ImageObserver.HEIGHT);
    }
    return height;
}
 
Example #22
Source File: ImageRepresentation.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public boolean drawToBufImage(Graphics g, ToolkitImage img,
                              int x, int y, Color bg,
                              ImageObserver iw) {

    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.ERROR) != 0) {
        if (iw != null) {
            iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
                           -1, -1, -1, -1);
        }
        return false;
    }
    boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
    boolean abort = ((availinfo & ImageObserver.ABORT) != 0);

    if (!done && !abort) {
        addWatcher(iw);
        startProduction();
        // Some producers deliver image data synchronously
        done = ((availinfo & ImageObserver.ALLBITS) != 0);
    }

    if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
        g.drawImage (bimage, x, y, bg, null);
    }

    return done;
}
 
Example #23
Source File: PeekGraphics.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Draws an image, applying a transform from image space into user space
     * before drawing.
     * The transformation from user space into device space is done with
     * the current transform in the Graphics2D.
     * The given transformation is applied to the image before the
     * transform attribute in the Graphics2D state is applied.
     * The rendering attributes applied include the clip, transform,
     * and composite attributes. Note that the result is
     * undefined, if the given transform is noninvertible.
     * @param img The image to be drawn.
     * @param xform The transformation from image space into user space.
     * @param obs The image observer to be notified as more of the image
     * is converted.
     * @see #transform
     * @see #setTransform
     * @see #setComposite
     * @see #clip
     * @see #setClip
     */
    public boolean drawImage(Image img,
                             AffineTransform xform,
                             ImageObserver obs) {

        if (img == null) {
            return true;
        }

        mDrawingArea.addInfinite();
        mPrintMetrics.drawImage(this, img);

        return mGraphics.drawImage(img, xform, obs);


//      if (mDrawingArea[0] != null) {
//          Rectangle2D.Double bbox = new Rectangle2D.Double();
//          Point2D leftTop = new Point2D.Double(0, 0);
//          Point2D rightBottom = new Point2D.Double(getImageWidth(img),
//                                                   getImageHeight(img));

//          xform.transform(leftTop, leftTop);
//          xform.transform(rightBottom, rightBottom);

//          bbox.setBoundsFromDiagonal(leftTop, rightBottom);
//          addDrawingRect(bbox);

//      }
    }
 
Example #24
Source File: EscherGraphics.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean drawImage(Image image, int i, int j, ImageObserver imageobserver)
{
    return drawImage(image, i, j, image.getWidth(imageobserver), image.getHeight(imageobserver), imageobserver);
}
 
Example #25
Source File: SunGraphics2D.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws an image scaled to x,y,w,h in nonblocking mode with a
 * solid background color and a callback object.
 */
public boolean drawImage(Image img, int x, int y, int width, int height,
                         Color bg, ImageObserver observer) {

    if (img == null) {
        return true;
    }

    if ((width == 0) || (height == 0)) {
        return true;
    }

    final int imgW = img.getWidth(null);
    final int imgH = img.getHeight(null);
    if (isHiDPIImage(img)) {
        return drawHiDPIImage(img, x, y, x + width, y + height, 0, 0, imgW,
                              imgH, bg, observer);
    }

    if (width == imgW && height == imgH) {
        return copyImage(img, x, y, 0, 0, width, height, bg, observer);
    }

    try {
        return imagepipe.scaleImage(this, img, x, y, width, height,
                                    bg, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, x, y, width, height,
                                        bg, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
 
Example #26
Source File: bug7172833.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int checkImage(final Image image, final int width, final int height,
                      final ImageObserver observer) {
    return 0;
}
 
Example #27
Source File: bug7172833.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int checkImage(final Image image, final int width, final int height,
                      final ImageObserver observer) {
    return 0;
}
 
Example #28
Source File: DrawImagePipe.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public boolean scaleImage(SunGraphics2D sg, Image img,
int dx1, int dy1, int dx2, int dy2,
int sx1, int sy1, int sx2, int sy2,
Color bgColor,
ImageObserver observer);
 
Example #29
Source File: FilteredImageSourceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getHeight(ImageObserver observer) {
    return 100;
}
 
Example #30
Source File: NullComponentPeer.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public int  checkImage(Image img, int w, int h, ImageObserver o) {
    return 0;
}