Java Code Examples for java.awt.Image.flush()

The following are Jave code examples for showing how to use flush() of the java.awt.Image class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: SplashBrandingPanel.java   View Source Code Vote up 6 votes
private void resetSplashPreview() throws NumberFormatException {
    Image oldImage = splashImage.image;
    if (null != oldImage)
        oldImage.flush();
    splashImage.setSplashImageIcon(splashSource);
    Rectangle tRectangle = (Rectangle)runningTextBounds.getValue();
    Rectangle pRectangle = (Rectangle)progressBarBounds.getValue();
    splashImage.setTextColor(textColor.getColor());
    splashImage.setColorBar(barColor.getColor());
    splashImage.setColorEdge(edgeColor.getColor());
    splashImage.setColorEdge(cornerColor.getColor());
    splashImage.setFontSize(((Number)fontSize.getValue()).intValue());
    splashImage.setRunningTextBounds(tRectangle);
    splashImage.setProgressBarBounds(pRectangle);
    splashImage.setProgressBarEnabled(progressBarEnabled.isSelected());
    splashImage.resetSteps();
    splashImage.setText(NbBundle.getMessage(getClass(),"TEXT_SplashSample")); //NOI18N
}
 
Example 2
Project: incubator-netbeans   File: ImageUtilities.java   View Source Code Vote up 6 votes
/** The method creates a BufferedImage which represents the same Image as the
 * parameter but consumes less memory.
 */
static final Image toBufferedImage(Image img) {
    // load the image
    new javax.swing.ImageIcon(img, "");

    if (img.getHeight(null)*img.getWidth(null) > 24*24) {
        return img;
    }
    java.awt.image.BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    java.awt.Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();

    return rep;
}
 
Example 3
Project: jdk8u-jdk   File: IncorrectClipSurface2SW.java   View Source Code Vote up 6 votes
private static void draw(Shape clip, Shape to, Image vi, BufferedImage bi,
                         int scale) {
    Graphics2D big = bi.createGraphics();
    big.setComposite(AlphaComposite.Src);
    big.setClip(clip);
    Rectangle toBounds = to.getBounds();
    int x1 = toBounds.x;

    int y1 = toBounds.y;
    int x2 = x1 + toBounds.width;
    int y2 = y1 + toBounds.height;
    big.drawImage(vi, x1, y1, x2, y2, 0, 0, toBounds.width / scale,
                  toBounds.height / scale, null);
    big.dispose();
    vi.flush();
}
 
Example 4
Project: openjdk-jdk10   File: IncorrectClipSurface2SW.java   View Source Code Vote up 6 votes
private static void draw(Shape clip, Shape to, Image vi, BufferedImage bi,
                         int scale) {
    Graphics2D big = bi.createGraphics();
    big.setComposite(AlphaComposite.Src);
    big.setClip(clip);
    Rectangle toBounds = to.getBounds();
    int x1 = toBounds.x;

    int y1 = toBounds.y;
    int x2 = x1 + toBounds.width;
    int y2 = y1 + toBounds.height;
    big.drawImage(vi, x1, y1, x2, y2, 0, 0, toBounds.width / scale,
                  toBounds.height / scale, null);
    big.dispose();
    vi.flush();
}
 
Example 5
Project: AdvancedServerListIcons   File: ImageHandler.java   View Source Code Vote up 5 votes
private BufferedImage toBufferedImage(Image image) {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    BufferedImage buffer = new BufferedImage(image.getWidth(null), image.getHeight(null), 2);
    Graphics2D g = buffer.createGraphics();
    g.drawImage(image, null, null);
    image.flush();
    return buffer;
}
 
Example 6
Project: incubator-netbeans   File: DecorableTest.java   View Source Code Vote up 5 votes
static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new javax.swing.ImageIcon(img, "");

    java.awt.image.BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    java.awt.Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();

    return rep;
}
 
Example 7
Project: incubator-netbeans   File: PropertyMarkingTest.java   View Source Code Vote up 5 votes
private static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new ImageIcon(img);
    BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();
    return rep;
}
 
Example 8
Project: incubator-netbeans   File: GraphicsTestCase.java   View Source Code Vote up 5 votes
private static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new ImageIcon(img);
    BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();
    return rep;
}
 
Example 9
Project: incubator-netbeans   File: ComboTest.java   View Source Code Vote up 5 votes
private static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new ImageIcon(img);
    BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();
    return rep;
}
 
Example 10
Project: incubator-netbeans   File: EditableDisplayerTest.java   View Source Code Vote up 5 votes
private static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new ImageIcon(img);
    BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();
    return rep;
}
 
Example 11
Project: incubator-netbeans   File: ComboTest.java   View Source Code Vote up 5 votes
private static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new javax.swing.ImageIcon(img);
    java.awt.image.BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    java.awt.Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();
    return rep;
}
 
Example 12
Project: incubator-netbeans   File: UINodeTest.java   View Source Code Vote up 5 votes
static final BufferedImage toBufferedImage(Image img) {
    // load the image
    new javax.swing.ImageIcon(img, "");

    java.awt.image.BufferedImage rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
    java.awt.Graphics g = rep.createGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    img.flush();

    return rep;
}
 
Example 13
Project: VisualGraphviz   File: Tools.java   View Source Code Vote up 5 votes
public static ImageIcon getScaledImageIcon(String path, int w, int h) {
    Image img = new ImageIcon("tmp.png").getImage();
    img.flush();
    
    int x = img.getWidth(null);
    int y = img.getHeight(null);
    double scale = Math.min((double) (w) / x, (double) (h) / y);
    x = (int) (x * scale);
    y = (int) (y * scale);
    return new ImageIcon(img.getScaledInstance(x, y, Image.SCALE_SMOOTH));
}
 
Example 14
Project: myfaces-trinidad   File: OffscreenWrappingPainter.java   View Source Code Vote up 4 votes
@Override
public void paint(
  PaintContext context,
  Graphics     g,
  int          x,
  int          y,
  int          width,
  int          height
  )
{
  // On X servers with limited color capacities, we have problems with
  // getting the background color of the offscreen image to match the
  // actual background color of the destination BufferedImage.  The
  // problem is that when the X server runs out of colors, it uses a
  // near match - which might not be the background color that we want.
  // The result is that the area behind the text may have a different
  // background color than the rest of the image.  (eg. in buttons, the
  // bounding box of the text has a white background, while the rest of
  // the button content is the light off-white specified by BLAF.)
  //
  // To work around this problem, we convert background pixels to
  // transparent before drawing the offscreen buffer.  However, we
  // can't simply filter on pixels where the rgb value is equal to
  // our desired background rgb value - as the actual rgb value is
  // picked by the X server.  So, we've got a real hack here...
  //
  // We make the offscreen buffer one pixel taller than needed.
  // We fill this entire area, including the extra pixel scan line
  // at the top, with the background color.  Then, we draw the content
  // starting at y=1.  So, when we get around to filtering the background,
  // we know that the pixels at y=0 are the background color - all pixel
  // values which match the value at 0, 0 are filtered to transparent.
  // Yeah, I know this is insane.  Feel free to rip this out if you've
  // got a better solution.

  // Create the offscreen buffer.  We make it one pixel taller than
  // necessary.  We want the top scan line to be filled with the background
  // color, but without any actual content, so that we can use it later
  // (during transparency filtering) to get the real background color.
  BufferedImage buffer = _createOffscreenBuffer(context, width, height + 1);

  if (buffer == null)
  {
    super.paint(context, g, x, y, width, height);
    return;
  }

  // If we've got a buffer, use it's graphics object for rendering
  // our wrapped painter
  Graphics offscreenG = _getInitializedGraphics(context, buffer);

  // Fill in the background - including the extra 1 pixel at the top
  offscreenG.setColor(context.getPaintBackground());
  offscreenG.fillRect(0, 0, width, height + 1);

  // Reset for text rendering
  offscreenG.setColor(g.getColor());
  offscreenG.translate(-x, -y);

  // Render the wrapped painter into the offscreen buffer.  We offset
  // the y coordinate by one so that no content will be rendered into
  // the top pixel.
  super.paint(context, offscreenG, x, y + 1, width, height);

  // Filter out the background
  Image transparentImage = ImageUtils.createFilteredImage(buffer,
                             new TransparencyFilter());
  ImageUtils.loadImage(transparentImage);

  // Now, render the transparent image into the original in Graphics object
  g.drawImage(transparentImage,
              x, y, x+width, y+height, 0, 1, width, height + 1, this);

  // Clean up
  offscreenG.dispose();
  transparentImage.flush();
  buffer.flush();
}
 
Example 15
Project: OpenJSharp   File: ImageCache.java   View Source Code Vote up 4 votes
/**
 * Sets the cached image for the specified constraints.
 *
 * @param image  The image to store in cache
 * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
 * @param w      The image width, used as part of cache key
 * @param h      The image height, used as part of cache key
 * @param args   Other arguments to use as part of the cache key
 * @return true if the image could be cached or false if the image is too big
 */
public boolean setImage(Image image, GraphicsConfiguration config, int w, int h, Object... args) {
    if (!isImageCachable(w, h)) return false;
    int hash = hash(config, w, h, args);
    lock.writeLock().lock();
    try {
        PixelCountSoftReference ref = map.get(hash);
        // check if currently in map
        if (ref != null && ref.get() == image) {
            return true;
        }
        // clear out old
        if (ref != null) {
            currentPixelCount -= ref.pixelCount;
            map.remove(hash);
        }
        // add new image to pixel count
        int newPixelCount = image.getWidth(null) * image.getHeight(null);
        currentPixelCount += newPixelCount;
        // clean out lost references if not enough space
        if (currentPixelCount > maxPixelCount) {
            while ((ref = (PixelCountSoftReference)referenceQueue.poll()) != null){
                //reference lost
                map.remove(ref.hash);
                currentPixelCount -= ref.pixelCount;
            }
        }
        // remove old items till there is enough free space
        if (currentPixelCount > maxPixelCount) {
            Iterator<Map.Entry<Integer, PixelCountSoftReference>> mapIter = map.entrySet().iterator();
            while ((currentPixelCount > maxPixelCount) && mapIter.hasNext()) {
                Map.Entry<Integer, PixelCountSoftReference> entry = mapIter.next();
                mapIter.remove();
                Image img = entry.getValue().get();
                if (img != null) img.flush();
                currentPixelCount -= entry.getValue().pixelCount;
            }
        }
        // finaly put new in map
        map.put(hash, new PixelCountSoftReference(image, referenceQueue, newPixelCount,hash, config, w, h, args));
        return true;
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 16
Project: OpenJSharp   File: CGLGraphicsConfig.java   View Source Code Vote up 4 votes
@Override
public void destroyBackBuffer(final Image backBuffer) {
    if (backBuffer != null) {
        backBuffer.flush();
    }
}
 
Example 17
Project: jdk8u-jdk   File: ImageCache.java   View Source Code Vote up 4 votes
/**
 * Sets the cached image for the specified constraints.
 *
 * @param image  The image to store in cache
 * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
 * @param w      The image width, used as part of cache key
 * @param h      The image height, used as part of cache key
 * @param args   Other arguments to use as part of the cache key
 * @return true if the image could be cached or false if the image is too big
 */
public boolean setImage(Image image, GraphicsConfiguration config, int w, int h, Object... args) {
    if (!isImageCachable(w, h)) return false;
    int hash = hash(config, w, h, args);
    lock.writeLock().lock();
    try {
        PixelCountSoftReference ref = map.get(hash);
        // check if currently in map
        if (ref != null && ref.get() == image) {
            return true;
        }
        // clear out old
        if (ref != null) {
            currentPixelCount -= ref.pixelCount;
            map.remove(hash);
        }
        // add new image to pixel count
        int newPixelCount = image.getWidth(null) * image.getHeight(null);
        currentPixelCount += newPixelCount;
        // clean out lost references if not enough space
        if (currentPixelCount > maxPixelCount) {
            while ((ref = (PixelCountSoftReference)referenceQueue.poll()) != null){
                //reference lost
                map.remove(ref.hash);
                currentPixelCount -= ref.pixelCount;
            }
        }
        // remove old items till there is enough free space
        if (currentPixelCount > maxPixelCount) {
            Iterator<Map.Entry<Integer, PixelCountSoftReference>> mapIter = map.entrySet().iterator();
            while ((currentPixelCount > maxPixelCount) && mapIter.hasNext()) {
                Map.Entry<Integer, PixelCountSoftReference> entry = mapIter.next();
                mapIter.remove();
                Image img = entry.getValue().get();
                if (img != null) img.flush();
                currentPixelCount -= entry.getValue().pixelCount;
            }
        }
        // finaly put new in map
        map.put(hash, new PixelCountSoftReference(image, referenceQueue, newPixelCount,hash, config, w, h, args));
        return true;
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 18
Project: jdk8u-jdk   File: CGLGraphicsConfig.java   View Source Code Vote up 4 votes
@Override
public void destroyBackBuffer(final Image backBuffer) {
    if (backBuffer != null) {
        backBuffer.flush();
    }
}
 
Example 19
Project: openjdk-jdk10   File: ImageCache.java   View Source Code Vote up 4 votes
/**
 * Sets the cached image for the specified constraints.
 *
 * @param image  The image to store in cache
 * @param config The graphics configuration, needed if cached image is a Volatile Image. Used as part of cache key
 * @param w      The image width, used as part of cache key
 * @param h      The image height, used as part of cache key
 * @param args   Other arguments to use as part of the cache key
 * @return true if the image could be cached or false if the image is too big
 */
public boolean setImage(Image image, GraphicsConfiguration config, int w, int h, Object... args) {
    if (!isImageCachable(w, h)) return false;
    int hash = hash(config, w, h, args);
    lock.writeLock().lock();
    try {
        PixelCountSoftReference ref = map.get(hash);
        // check if currently in map
        if (ref != null && ref.get() == image) {
            return true;
        }
        // clear out old
        if (ref != null) {
            currentPixelCount -= ref.pixelCount;
            map.remove(hash);
        }
        // add new image to pixel count
        int newPixelCount = image.getWidth(null) * image.getHeight(null);
        currentPixelCount += newPixelCount;
        // clean out lost references if not enough space
        if (currentPixelCount > maxPixelCount) {
            while ((ref = (PixelCountSoftReference)referenceQueue.poll()) != null){
                //reference lost
                map.remove(ref.hash);
                currentPixelCount -= ref.pixelCount;
            }
        }
        // remove old items till there is enough free space
        if (currentPixelCount > maxPixelCount) {
            Iterator<Map.Entry<Integer, PixelCountSoftReference>> mapIter = map.entrySet().iterator();
            while ((currentPixelCount > maxPixelCount) && mapIter.hasNext()) {
                Map.Entry<Integer, PixelCountSoftReference> entry = mapIter.next();
                mapIter.remove();
                Image img = entry.getValue().get();
                if (img != null) img.flush();
                currentPixelCount -= entry.getValue().pixelCount;
            }
        }
        // finaly put new in map
        map.put(hash, new PixelCountSoftReference(image, referenceQueue, newPixelCount,hash, config, w, h, args));
        return true;
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 20
Project: openjdk-jdk10   File: CGLGraphicsConfig.java   View Source Code Vote up 4 votes
@Override
public void destroyBackBuffer(final Image backBuffer) {
    if (backBuffer != null) {
        backBuffer.flush();
    }
}