java.awt.Image.flush()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(412)

本文整理了Java中java.awt.Image.flush()方法的一些代码示例,展示了Image.flush()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Image.flush()方法的具体详情如下:
包路径:java.awt.Image
类名称:Image
方法名:flush

Image.flush介绍

[英]Flushes all resources being used by this Image object. This includes any pixel data that is being cached for rendering to the screen as well as any system resources that are being used to store data or pixels for the image. The image is reset to a state similar to when it was first created so that if it is again rendered, the image data will have to be recreated or fetched again from its source.

This method always leaves the image in a state such that it can be reconstructed. This means the method applies only to cached or other secondary representations of images such as those that have been generated from an ImageProducer (read from a file, for example). It does nothing for off-screen images that have only one copy of their data.
[中]刷新此图像对象正在使用的所有资源。这包括缓存以渲染到屏幕的任何像素数据,以及用于存储图像数据或像素的任何系统资源。图像将重置为与第一次创建时类似的状态,因此如果再次渲染,则必须重新创建图像数据或从其源重新获取图像数据。
这种方法总是使图像处于可以重建的状态。这意味着该方法仅适用于图像的缓存或其他二级表示,例如从ImageProducer生成的图像(例如,从文件读取)。它对只有一份数据拷贝的屏幕外图像没有任何作用。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-util

/** 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;
}

代码示例来源:origin: plantuml/plantuml

private static BufferedImage readImage(final ImageIcon imageIcon) {
  final Image tmpImage = imageIcon.getImage();
  final BufferedImage image = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(),
      BufferedImage.TYPE_INT_ARGB);
  image.getGraphics().drawImage(tmpImage, 0, 0, null);
  tmpImage.flush();
  return image;
}

代码示例来源:origin: stackoverflow.com

h = Math.max(h/2, height);
img = commonResize(prev, w, h, hint);
prev.flush();

代码示例来源:origin: org.netbeans.api/org-openide-util-ui

/** 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;
}

代码示例来源:origin: org.fudaa.framework.ebli/ebli-2d

/**
 * @param _useCache the useCache to set
 */
public void setUseCache(boolean _useCache) {
 useCache_ = _useCache;
 if (!_useCache && cache_ != null) {
  cache_.flush();
  cache_ = null;
 }
}

代码示例来源:origin: net.imagej/ij

void resetPixels(Object pixels) {
  if (pixels==null) {
    if (img!=null) {
      img.flush();
      img = null;
    }
  }
}

代码示例来源:origin: de.sciss/scisslib

private void flushImage() {
  if (limited != null) {
    limited.flush();
    limited = null;
  }
}

代码示例来源:origin: senbox-org/s1tbx

@Override
protected void finalize()
    throws Throwable {
  if (colorBar != null)
    colorBar.flush();
  colorBar = null;
  super.finalize();
}

代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod

/**
 * Schedules the offscreen resources taken by the offscreen buffer to
 * be reclaimed. Note that this does not force garbage collection
 */
public void releaseOffscreenResources() {
  offscreen.flush();
  offgraphics.dispose();
  offscreen = null;
  offgraphics = null;
}

代码示例来源:origin: de.mhus.lib/mhu-lib-core

public static BufferedImage toBufferedImage(Image _in, int _width,
    int _height) {
  BufferedImage out = new BufferedImage(_width, _height,
      BufferedImage.TYPE_3BYTE_BGR);
  Graphics g = out.getGraphics();
  g.drawImage(_in, 0, 0, _width, _height, null);
  _in.flush();
  return out;
}

代码示例来源:origin: org.icepdf.os/icepdf-core

public static BufferedImage createBufferedImage(Image imageIn,
                        int imageType) {
  BufferedImage bufferedImageOut = new BufferedImage(imageIn
      .getWidth(null), imageIn.getHeight(null), imageType);
  Graphics g = bufferedImageOut.getGraphics();
  g.drawImage(imageIn, 0, 0, null);
  imageIn.flush();
  return bufferedImageOut;
}

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

/** 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);
  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;
}

代码示例来源:origin: stackoverflow.com

ImageIcon imageIcon = new ImageIcon(imageAbsolutePath);
 Image tmpImage = imageIcon.getImage();
 BufferedImage image = new BufferedImage(imageIcon.getIconWidth(), imageIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
 image.getGraphics().drawImage(tmpImage, 0, 0, null);
 tmpImage.flush();
 return image;

代码示例来源:origin: triplea-game/triplea

public void loadMaps(final ResourceLoader loader) {
 final Image smallFromFile = loadImage(loader, Constants.SMALL_MAP_FILENAME, Constants.SMALL_MAP_EXTENSIONS);
 smallMapImage = Util.newImage(smallFromFile.getWidth(null), smallFromFile.getHeight(null), false);
 final Graphics g = smallMapImage.getGraphics();
 g.drawImage(smallFromFile, 0, 0, null);
 g.dispose();
 smallFromFile.flush();
}

代码示例来源:origin: sc.fiji/TrakEM2_

static public final boolean saveAsPNG(final ImageProcessor ip, final String path) {
  Image awt = null;
  try {
    awt = ip.createImage();
    return ImageSaver.saveAsPNG(awt, path);
  } catch (Exception e) {
    IJError.print(e);
    return false;
  } finally {
    if (null != awt) awt.flush();
  }
}

代码示例来源:origin: sc.fiji/fiji-lib

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();
}

代码示例来源:origin: infiniteautomation/ma-core-public

public static byte[] scaleImage(BaseScaledImage scaler, Image image, BaseImageFormat encodingFormat)
    throws IOException {
  scaler.scaleImage(image);
  byte[] result = encodeImage(scaler.getScaledImage(), encodingFormat);
  scaler.flush();
  image.flush();
  return result;
}

代码示例来源:origin: sc.fiji/TrakEM2_

protected BufferedImage makeImage( final ImageProcessor ip, final FloatProcessor mask )
{
  final BufferedImage transformedImage = new BufferedImage( ip.getWidth(), ip.getHeight(), null == mask ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB );
  final Image img = ip.createImage();
  transformedImage.createGraphics().drawImage( img, 0, 0, null );
  img.flush();
  if (null != mask) {
    transformedImage.getAlphaRaster().setPixels( 0, 0, ip.getWidth(), ip.getHeight(), ( float[] )mask.getPixels() );
  }
  return transformedImage;
}

代码示例来源:origin: sc.fiji/TrakEM2_

/** Flush all mipmaps, and forget all mipmaps and imps. */
public final void removeAndFlushAll() {
  for (final Pyramid p : pyramids.values()) {
    p.replace(null); // the imp may need cleanup
    for (int i=0; i<p.images.length; i++) {
      if (null == p.images[i]) continue;
      p.images[i].flush(); CachingThread.storeArrayForReuse(p.images[i]);
    }
  }
  reset();
}

代码示例来源:origin: sc.fiji/TrakEM2_

public ImagePlus getFlatImage(final Layer layer, final Rectangle srcRect_, final double scale, final int c_alphas, final int type, final Class<?> clazz, final List<? extends Displayable> al_displ, final boolean quality, final Color background, final Displayable active) {
  final Image bi = getFlatAWTImage(layer, srcRect_, scale, c_alphas, type, clazz, al_displ, quality, background, active);
  final ImagePlus imp = new ImagePlus(layer.getPrintableTitle(), bi);
  final Calibration impCalibration = layer.getParent().getCalibrationCopy();
  impCalibration.pixelWidth /= scale;
  impCalibration.pixelHeight /= scale;
  imp.setCalibration(impCalibration);
  bi.flush();
  return imp;
}

相关文章