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

x33g5p2x  于2022-01-16 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(809)

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

BufferedImage.flush介绍

[英]Flushes all resources being used to cache optimization information. The underlying pixel data is unaffected.
[中]刷新用于缓存优化信息的所有资源。底层像素数据不受影响。

代码示例

代码示例来源:origin: sarxos/webcam-capture

@Override
public BufferedImage getImage() {
  if (!open) {
    throw new RuntimeException("Webcam has to be open to get image");
  }
  Buffer buffer = grabber.grabFrame();
  Image image = converter.createImage(buffer);
  if (image == null) {
    throw new RuntimeException("Cannot get image");
  }
  int width = image.getWidth(null);
  int height = image.getHeight(null);
  int type = BufferedImage.TYPE_INT_RGB;
  BufferedImage buffered = new BufferedImage(width, height, type);
  Graphics2D g2 = buffered.createGraphics();
  g2.drawImage(image, null, null);
  g2.dispose();
  buffered.flush();
  return buffered;
}

代码示例来源:origin: sarxos/webcam-capture

@Override
public void rgbFrame(boolean preroll, int width, int height, IntBuffer rgb) {
  LOG.trace("New RGB frame");
  if (t1 == -1 || t2 == -1) {
    t1 = System.currentTimeMillis();
    t2 = System.currentTimeMillis();
  }
  BufferedImage tmp = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  tmp.setAccelerationPriority(0);
  rgb.get(((DataBufferInt) tmp.getRaster().getDataBuffer()).getData(), 0, width * height);
  tmp.flush();
  image = tmp;
  if (starting.compareAndSet(true, false)) {
    synchronized (this) {
      this.notifyAll();
    }
    LOG.debug("GStreamer device ready");
  }
  t1 = t2;
  t2 = System.currentTimeMillis();
  fps = (4 * fps + 1000 / (t2 - t1 + 1)) / 5;
}

代码示例来源:origin: sarxos/webcam-capture

@Override
public BufferedImage getImage() {
  ByteBuffer buffer = getImageBytes();
  if (buffer == null) {
    LOG.error("Images bytes buffer is null!");
    return null;
  }
  byte[] bytes = new byte[size.width * size.height * 3];
  byte[][] data = new byte[][] { bytes };
  buffer.get(bytes);
  DataBufferByte dbuf = new DataBufferByte(data, bytes.length, OFFSET);
  WritableRaster raster = Raster.createWritableRaster(smodel, dbuf, null);
  BufferedImage bi = new BufferedImage(cmodel, raster, false, null);
  bi.flush();
  return bi;
}

代码示例来源:origin: JpressProjects/jpress

/**
 * 等比缩放,居中剪切
 *
 * @param src
 * @param dest
 * @param w
 * @param h
 * @throws IOException
 */
public static void scale(String src, String dest, int w, int h) throws IOException {
  if (notImageExtName(src)) {
    throw new IllegalArgumentException("只支持如下几种图片格式:jpg、jpeg、png、bmp");
  }
  Iterator<ImageReader> iterator = ImageIO.getImageReadersByFormatName(getExtName(src));
  ImageReader reader = (ImageReader) iterator.next();
  InputStream in = new FileInputStream(src);
  ImageInputStream iis = ImageIO.createImageInputStream(in);
  reader.setInput(iis);
  BufferedImage srcBuffered = readBuffereImage(reader, w, h);
  BufferedImage targetBuffered = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
  Graphics graphics = targetBuffered.getGraphics();
  graphics.drawImage(srcBuffered.getScaledInstance(w, h, Image.SCALE_DEFAULT), 0, 0, null); // 绘制缩小后的图
  graphics.dispose();
  srcBuffered.flush();
  save(targetBuffered, dest);
  targetBuffered.flush();
}

代码示例来源:origin: nutzam/nutz

/**
 * 生成该图片对应的 Base64 编码的字符串
 * 
 * @param targetFile
 *            图片文件
 * @return 图片对应的 Base64 编码的字符串
 */
public static String encodeBase64(File targetFile) {
  BufferedImage image = null;
  try {
    image = ImageIO.read(targetFile);
  }
  catch (IOException e) {
    throw Lang.wrapThrow(e);
  }
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  BufferedOutputStream bos = new BufferedOutputStream(baos);
  image.flush();
  try {
    ImageIO.write(image, Files.getSuffixName(targetFile), bos);
    bos.flush();
    bos.close();
  }
  catch (IOException e) {
    throw Lang.wrapThrow(e);
  }
  byte[] bImage = baos.toByteArray();
  return Base64.encodeToString(bImage, false);
}

代码示例来源:origin: org.apache.poi/poi

public void dispose()
{
  getEscherGraphics().dispose();
  getG2D().dispose();
  getImg().flush();
}

代码示例来源:origin: sarxos/webcam-capture

bi.flush();

代码示例来源:origin: sarxos/webcam-capture

@Override
public void open() {
  if (!open.compareAndSet(false, true)) {
    return;
  }
  LOG.debug("Opening GStreamer device");
  init();
  starting.set(true);
  Dimension size = getResolution();
  image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
  image.setAccelerationPriority(0);
  image.flush();
  if (caps != null) {
    caps.dispose();
  }
  caps = Caps.fromString(String.format("%s,framerate=30/1,width=%d,height=%d", format, size.width, size.height));
  filter.setCaps(caps);
  LOG.debug("Using filter caps: {}", caps);
  pipelinePlay();
  LOG.debug("Wait for device to be ready");
  // wait max 20s for image to appear
  synchronized (this) {
    try {
      this.wait(20000);
    } catch (InterruptedException e) {
      return;
    }
  }
}

代码示例来源:origin: sarxos/webcam-capture

image.flush();

代码示例来源:origin: sarxos/webcam-capture

resizedImage.flush();

代码示例来源:origin: org.apache.poi/poi-ooxml

img.flush();

代码示例来源:origin: rkalla/imgscalr

src.flush();

代码示例来源:origin: rkalla/imgscalr

src.flush();

代码示例来源:origin: org.apache.poi/poi

g.drawImage(img, 0, 0, null);
g.dispose();
img.flush();
img = argbImg;

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

@Override
public void out(OutputStream os) {
  try {
    GifEncoder gifEncoder = new GifEncoder(); // gif编码类,这个利用了洋人写的编码类,所有类都在附件中
    // 生成字符
    gifEncoder.start(os);
    gifEncoder.setQuality(180);
    gifEncoder.setDelay(100);
    gifEncoder.setRepeat(0);
    BufferedImage frame;
    char[] rands = alphas();
    Color[] fontcolor = new Color[len];
    for (int i = 0; i < len; i++) {
      fontcolor[i] = new Color(20 + num(110), 20 + num(110), 20 + num(110));
    }
    for (int i = 0; i < len; i++) {
      frame = graphicsImage(fontcolor, rands, i);
      gifEncoder.addFrame(frame);
      frame.flush();
    }
    gifEncoder.finish();
  } finally {
    try {
      os.close();
    } catch (IOException e) {
      log.error(e.getMessage());
    }
  }
}

代码示例来源:origin: coobird/thumbnailator

sourceImage.flush();
destinationImage.flush();

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

private static BufferedImage createImage(Iterable<?> objects, Visualizer visualizer, Rectangle2D bounds, Color backgroundColor) {
  final int width = (int) Math.round(bounds.getWidth());
  final int height = (int) Math.round(bounds.getHeight());
  BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = img.createGraphics();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  if (backgroundColor != null) {
    g.setColor(backgroundColor);
    g.fillRect(0, 0, width, height);
  }
  g.translate(-bounds.getX(), -bounds.getY());
  visualizer.draw(g, objects);
  img.flush();
  return img;
}

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

public BufferedImage asImage() {
  Rect bounds = getBounds();
  BufferedImage img = new BufferedImage((int) Math.round(bounds.getWidth()), (int) Math.round(bounds.getHeight()), BufferedImage.TYPE_INT_ARGB);
  Graphics2D g = img.createGraphics();
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.translate(-bounds.getX(), -bounds.getY());
  draw(g);
  img.flush();
  return img;
}

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

/**
 * Provides a hint that this {@link ImageWorker} will no longer be accessed from a reference in
 * user space. The results are equivalent to those that occur when the program loses its last
 * reference to this image, the garbage collector discovers this, and finalize is called. This
 * can be used as a hint in situations where waiting for garbage collection would be overly
 * conservative.
 *
 * <p>Mind, this also results in disposing the JAI Image chain attached to the image the worker
 * is applied to, so don't call this method on image changes (full/partial) that you want to
 * use.
 *
 * <p>{@link ImageWorker} defines this method to remove the image being disposed from the list
 * of sinks in all of its source images. The results of referencing an {@link ImageWorker} after
 * a call to dispose() are undefined.
 */
public final void dispose() {
  if (commonHints != null) {
    this.commonHints.clear();
  }
  this.commonHints = null;
  this.roi = null;
  if (this.image instanceof PlanarImage) {
    ImageUtilities.disposePlanarImageChain(PlanarImage.wrapRenderedImage(image));
  } else if (this.image instanceof BufferedImage) {
    ((BufferedImage) this.image).flush();
    this.image = null;
  }
}

代码示例来源:origin: 0opslab/opslabJutil

frame.flush();

相关文章