private Image createOffscreenImage() { switch (bufferType) { case BUFFER_VOLATILE_IMAGE: // Flush current offscreen image to release resources if (offscreenImage != null) offscreenImage.flush(); return createVolatileImage(getWidth(), getHeight()); case BUFFER_IMAGE: // Flush current offscreen image to release resources // TODO: is flush() really needed for BufferedImage? if (offscreenImage != null) offscreenImage.flush(); return createImage(getWidth(), getHeight()); default: return null; } }
public synchronized void setClickImage(Image on, Image un) { if (un == null) { return; } if (bitmap != null) { bitmap.flush(); bitmap = null; } if (bitmap1 != null) { bitmap1.flush(); bitmap1 = null; } this.bitmap = un == null ? on : un; this.bitmap1 = on == null ? ImageFilterFactory.getGray(un) : on; this.setSize(un.getWidth(null), un.getHeight(null)); }
@Override protected void finalize() throws Throwable { Image img = getImage(); if (img != null) img.flush(); data = null; super.finalize(); }
private void initialise() { Toolkit toolkit = Toolkit.getDefaultToolkit(); backBuffer = worldMap.getGraphics(); // Make the image buffer as large as could possibly be used (screensize) if (backBufferImage == null) { logger.debug( "Creating backBufferImage of dimensions " + toolkit.getScreenSize().width + "," + toolkit.getScreenSize().height + "."); backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height); backBuffer = backBufferImage.getGraphics(); } else { backBufferImage.flush(); backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height); backBuffer.dispose(); backBuffer = backBufferImage.getGraphics(); } setupWindow(worldMap.getWidth(), worldMap.getHeight()); initialise = false; logger.debug( "initialised backBufferImage with size " + worldMap.getWidth() + "," + worldMap.getHeight() + "."); }
/** * Scales an image to fit within the current size thresholds. * * @param img the image to scale * @return the scaled image */ protected Image getScaledImage(Image img) { // resize image, if necessary, to conserve memory // and reduce future scaling time int w = img.getWidth(null) - m_maxImageWidth; int h = img.getHeight(null) - m_maxImageHeight; if (w > h && w > 0 && m_maxImageWidth > -1) { Image scaled = img.getScaledInstance(m_maxImageWidth, -1, Image.SCALE_SMOOTH); img.flush(); // waitForImage(scaled); return scaled; } else if (h > 0 && m_maxImageHeight > -1) { Image scaled = img.getScaledInstance(-1, m_maxImageHeight, Image.SCALE_SMOOTH); img.flush(); // waitForImage(scaled); return scaled; } else { return img; } }
@Override public final void destroyBuffers() { final Image oldBB = getBackBuffer(); synchronized (getStateLock()) { backBuffer = null; } if (oldBB != null) { oldBB.flush(); } }
public void dispose() { if (bigImageMap != null) { bigImageMap.flush(); bigImageMap = null; } if (chips != null) { chips = null; } if (field2d != null) { field2d = null; } }
public void setBigImageMap(Image img) { if (img != null) { this.bigImageMap = GraphicsUtils.drawClipImage(img, drawWidth, drawHeight, 0, 0); if (img != null) { img.flush(); img = null; } this.fieldMode = SRPGType.FIELD_BIGMAP; } else { this.fieldMode = SRPGType.FIELD_NORMAL; } }
public Image getPosImage(int x, int y) { if (x < 0 || y < 0 || posX >= width || posY >= height) { return null; } switch (fieldMode) { case SRPGType.FIELD_NORMAL: return battleList.getBattleElement(getPosChips(x, y)).image; case SRPGType.FIELD_BIGMAP: if (bigImageMap == null) { return null; } else { Image tmp = tempFieldImage; tempFieldImage = GraphicsUtils.drawClipImage( bigImageMap, tileWidth, tileHeight, x * tileWidth, y * tileHeight); if (tmp != null) { tmp.flush(); tmp = null; } return tempFieldImage; } case SRPGType.FIELD_BLEND: if (bigImageMap == null) { return battleList.getBattleElement(getPosChips(x, y)).image; } else { Image tmp = tempFieldImage; tempFieldImage = GraphicsUtils.drawClipImage( bigImageMap, tileWidth, tileHeight, x * tileWidth, y * tileHeight); if (tmp != null) { tmp.flush(); tmp = null; } return tempFieldImage; } } return battleList.getBattleElement(getPosChips(x, y)).image; }
/** * @param _old * @param _w * @param _h * @return */ public static Image ensureBuffer(Image _old, int _w, int _h) { if (_w == 0 || _h == 0) { Image newBuffer = newBuffer(1, 1); if (_old != null) { _old.flush(); } return newBuffer; } if (_old == null) { Image newBuffer = newBuffer(_w, _h); return newBuffer; } else { if (_old.getWidth(null) != _w || _old.getHeight(null) != _h) { Image newBuffer = newBuffer(_w, _h); Graphics bg = newBuffer.getGraphics(); bg.drawImage(_old, 0, 0, null); bg.dispose(); _old.flush(); return newBuffer; } return _old; } }
private void resetBackBuffer() { if (backBufferGraphics != null) { backBufferGraphics.dispose(); backBufferGraphics = null; } if (backBufferImage != null) { backBufferImage.flush(); backBufferImage = null; } backBufferWidth = getSize().width; backBufferHeight = getSize().height; backBufferImage = createImage(backBufferWidth, backBufferHeight); backBufferGraphics = backBufferImage.getGraphics(); }
public void paint(Graphics g) { Dimension osize = getSize(); if ((buffer == null) || (osize.height != buffer.getHeight(null)) || (osize.width != buffer.getWidth(null))) { if (buffer != null) { buffer.flush(); } buffer = createImage(osize.width, osize.height); } Graphics gc = buffer.getGraphics(); drawAll(gc); g.drawImage(buffer, 0, 0, this); gc.dispose(); }
void scaleImages(String nameOfChangedImage) { if (SnapshotGallery.sharedInstance().isEmpty()) { return; } if (EventQueue.isDispatchThread()) setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); float w = 0, h = 0; Insets insets = getInsets(); int w1 = insets.left + insets.right; int h1 = insets.top + insets.bottom + IMAGE_HEIGHT; int n = SnapshotGallery.sharedInstance().size(); String name = null; ImageIcon icon = null; Image image = null; float r = 1; for (int i = n - 1; i >= 0; i--) { name = SnapshotGallery.sharedInstance().getImageName(i); image = SnapshotGallery.sharedInstance().getThumbnail(i); if (image == null || name.equals(nameOfChangedImage)) { icon = SnapshotGallery.sharedInstance().loadAnnotatedImage(i); w = icon.getIconWidth(); h = icon.getIconHeight(); r = IMAGE_HEIGHT / h; w *= r; // This scaling method causes out-of-memory error: // icon.getImage().getScaledInstance((int) w, IMAGE_HEIGHT, Image.SCALE_SMOOTH); image = ModelerUtilities.scale((BufferedImage) icon.getImage(), r, r); SnapshotGallery.sharedInstance().putThumbnail(icon.getDescription(), image); image.flush(); icon.getImage().flush(); } else { w = image.getWidth(this); h = image.getHeight(this); } if (getLayout() instanceof FlowLayout) { w1 += (int) w + ((FlowLayout) getLayout()).getHgap(); } else { w1 += (int) w + IMAGE_GAP; } } setPreferredSize(new Dimension(w1, h1)); if (EventQueue.isDispatchThread()) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
private void createImage2() { java.awt.Image img2 = createImage(height, width); Graphics g = img2.getGraphics(); g.setColor(Color.lightGray); g.fillRect(0, 0, height, width); g.setColor(Color.black); FontMetrics fm = g.getFontMetrics(); String str = "Work Unit keyrate (kkeys/sec)"; int length = fm.stringWidth(str); g.drawString(str, (height / 2) - length / 2, fm.getHeight()); g.dispose(); g.finalize(); img2.flush(); int[] pixels = new int[height * width]; PixelGrabber pg = new PixelGrabber(img2, 0, 0, height, width, pixels, 0, height); try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return; } /* Rotate the Image */ int pixels2[] = new int[height * width]; for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int c = pixels[y + (x) * height]; // Due a bug in the MS-JavaVM the Background for Images are not the same // as for Panel's so. mark it as non-opaque .. if (c != 0xff000000) { c = 0; } pixels2[x + (height - y - 1) * width] = c; } img = createImage(new MemoryImageSource(width, height, pixels2, 0, width)); repaint(); }
/** * Retrieves the dimensions of this image using <code>ImageIO</code> classes or an <code> * ImageObserver</code>. */ public static Dimension get(File file) { if (file == null) throw new NullPointerException(); try { Dimension size = getSizeUsingImageIO(file); return size; } catch (Exception e) { try { Image image = Toolkit.getDefaultToolkit().createImage(file.getAbsolutePath()); try { return get(image); } finally { image.flush(); } } catch (Exception e2) { IllegalArgumentException e3 = new IllegalArgumentException("could not fetch dimensions of " + file.getAbsolutePath()); e3.initCause(e2); e2.initCause(e); throw e3; } } }
public void paintObjects(LGraphics g, int minX, int minY, int maxX, int maxY) { if (objects == null) { return; } synchronized (objects) { int paintSeq = 0; boolean isListener = false; Iterator iter = objects.iterator(); Actor thing = null; while (iter.hasNext()) { thing = (Actor) iter.next(); if (!thing.isVisible()) { continue; } isListener = (thing.actorListener != null); thing.update(elapsedTime); if (isListener) { thing.actorListener.update(elapsedTime); } RectBox rect = thing.getRectBox(); int actorX = minX + thing.getX(); int actorY = minY + thing.getY(); int actorWidth = rect.getWidth(); int actorHeight = rect.getHeight(); if (actorX + actorWidth < minX || actorX > maxX || actorY + actorHeight < minY || actorY > maxY) { continue; } LImage actorImage = thing.getImage(); if (actorImage != null) { thing.setLastPaintSeqNum(paintSeq++); boolean isBitmapFilter = ImageFilterType.NoneFilter != thing.filterType; Image bitmap = actorImage.getBufferedImage(); if (isBitmapFilter) { bitmap = factory.doFilter(bitmap, thing.filterType); } int rotation = thing.getRotation(); if (thing.alpha < 1.0) { g.setAlpha(thing.alpha); } if (rotation != 0) { double halfWidth = actorImage.getWidth() / 2; double halfHeight = actorImage.getHeight() / 2; double newWidth = actorX + halfWidth; double newHeight = actorY + halfHeight; atform.setToIdentity(); atform.scale(thing.scaleX, thing.scaleY); atform.translate(newWidth, newHeight); atform.rotate(Math.toRadians(rotation)); atform.translate(-newWidth, -newHeight); atform.translate(actorX, actorY); g.drawImage(bitmap, atform); } else { int width = (int) (actorImage.getWidth() * thing.scaleX); int height = (int) (actorImage.getHeight() * thing.scaleY); g.drawImage(bitmap, actorX, actorY, width, height); } if (isBitmapFilter) { bitmap.flush(); bitmap = null; } if (thing.alpha < 1.0) { g.setAlpha(1.0F); } } if (actorX == 0 && actorY == 0) { thing.draw(g); if (isListener) { thing.actorListener.draw(g); } } else { g.translate(actorX, actorY); thing.draw(g); if (isListener) { thing.actorListener.draw(g); } g.translate(-actorX, -actorY); } } } }
public void clearData() { if (data != null && !(data instanceof java.awt.Font)) { if (data instanceof Image) ((Image) data).flush(); setData(null); } }
/** * Releases reference to the offscreen image. The image will be re-created and its entire area * painted on next paintComponent(Graphics) invocation. */ protected final void releaseOffscreenImage() { if (offscreenImage != null) offscreenImage.flush(); offscreenImage = null; offscreenImageReference.clear(); }
/** * Releases reference to the offscreen image but keeps a weak reference. The image will be reused * on next paintComponent(Graphics) invocation if still referenced, otherwise it will be * re-created. * * <p>Note that invocation of this method doesn't invalidate the offscreen image, it will be * eventually reused without updating. To be sure that reused image will be updated on next * paintComponent(Graphics) invocation, invoke the invalidateOffscreenImage() or * invalidateOffscreenImage(Rectangle) method after weakly releasing the offscreen image. */ protected final void weaklyReleaseOffscreenImage() { if (offscreenImage != null) offscreenImage.flush(); offscreenImage = null; }
public void onDispose() { if (image != null) { image.flush(); image = null; } }
public SequenceIterator call(SequenceIterator[] arguments, XPathContext context) throws XPathException { String imageFn = ((StringValue) arguments[0].next()).getStringValue(); imageLoaded = false; imageFailed = false; image = null; width = -1; depth = -1; System.setProperty("java.awt.headless", "true"); try { URL url = new URL(imageFn); image = Toolkit.getDefaultToolkit().getImage(url); } catch (MalformedURLException mue) { image = Toolkit.getDefaultToolkit().getImage(imageFn); } width = image.getWidth(this); depth = image.getHeight(this); while (!imageFailed && (width == -1 || depth == -1)) { try { java.lang.Thread.currentThread().sleep(50); } catch (Exception e) { // nop; } width = image.getWidth(this); depth = image.getHeight(this); } image.flush(); if ((width == -1 || depth == -1) && imageFailed) { // Maybe it's an EPS or PDF? // FIXME: this code is crude BufferedReader ir = null; String line = null; int lineLimit = 100; try { ir = new BufferedReader(new FileReader(new File(imageFn))); line = ir.readLine(); if (line != null && line.startsWith("%PDF-")) { // We've got a PDF! while (lineLimit > 0 && line != null) { lineLimit--; if (line.startsWith("/CropBox [")) { line = line.substring(10); if (line.indexOf("]") >= 0) { line = line.substring(0, line.indexOf("]")); } parseBox(line); lineLimit = 0; } line = ir.readLine(); } } else if (line != null && line.startsWith("%!") && line.indexOf(" EPSF-") > 0) { // We've got an EPS! while (lineLimit > 0 && line != null) { lineLimit--; if (line.startsWith("%%BoundingBox: ")) { line = line.substring(15); parseBox(line); lineLimit = 0; } line = ir.readLine(); } } else if (line != null && (line.startsWith("<?xml") || line.startsWith("<!DOCTYPE") || line.startsWith("<svg"))) { // We've got an SVG! while (lineLimit > 0 && line != null) { lineLimit--; if (line.contains("width=") && width == -1) { int pos = line.indexOf("width="); String ex = line.substring(pos + 7); int sqpos = ex.indexOf("'"); int dqpos = ex.indexOf("\""); pos = sqpos < dqpos && sqpos >= 0 ? sqpos : dqpos; width = convertUnits(ex.substring(0, pos)); } if (line.contains("height=") && depth == -1) { int pos = line.indexOf("height="); String ex = line.substring(pos + 8); int sqpos = ex.indexOf("'"); int dqpos = ex.indexOf("\""); pos = sqpos < dqpos && sqpos >= 0 ? sqpos : dqpos; depth = convertUnits(ex.substring(0, pos)); } if (width >= 0 && depth >= 0) { lineLimit = 0; } line = ir.readLine(); } } else { System.err.println("Failed to interpret image: " + imageFn); } } catch (Exception e) { System.err.println("Failed to load image: " + imageFn); width = -1; depth = -1; } if (ir != null) { try { ir.close(); } catch (Exception e) { // nop; } } } if (width >= 0) { Int64Value[] props = {new Int64Value(width), new Int64Value(depth)}; return new ArrayIterator(props); } else { return EmptyIterator.getInstance(); } }
public void invalidate() { super.invalidate(); if (offscreen != null) offscreen.flush(); offscreen = null; }
public void flush() { real.flush(); }
public final void paint(final Graphics g) { final Rectangle bounds = getBounds(); if (myAnchor == ToolWindowAnchor.LEFT) { if (myDirection == 1) { g.setClip(null); g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, myOffset - bounds.width, 0, null); } else { g.setClip(null); g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, -myOffset, 0, null); } myTopImage.flush(); } else if (myAnchor == ToolWindowAnchor.RIGHT) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, bounds.width - myOffset, 0, null); } else { g.setClip(null); g.clipRect(0, 0, myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, myOffset, 0, null); } } else if (myAnchor == ToolWindowAnchor.TOP) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width, myOffset); UIUtil.drawImage(g, myTopImage, 0, -bounds.height + myOffset, null); } else { g.setClip(null); g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myTopImage, 0, -myOffset, null); } } else if (myAnchor == ToolWindowAnchor.BOTTOM) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, 0, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset); UIUtil.drawImage(g, myTopImage, 0, bounds.height - myOffset, null); } else { g.setClip(null); g.clipRect(0, 0, bounds.width, myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myTopImage, 0, myOffset, null); } } }