当前位置: 首页>>代码示例>>Java>>正文


Java BufferedImage.flush方法代码示例

本文整理汇总了Java中java.awt.image.BufferedImage.flush方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.flush方法的具体用法?Java BufferedImage.flush怎么用?Java BufferedImage.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.BufferedImage的用法示例。


在下文中一共展示了BufferedImage.flush方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Convert {@link AbstractImage} to {@link Image}.
 *
 * @param in
 *            the input image
 * @return the converted image
 */
public static Image toImage(AbstractImage in) {
	if (in == null) {
		return null;
	}
	BufferedImage res = new BufferedImage(in.width, in.height, BufferedImage.TYPE_INT_ARGB);
	int[] pixels = new int[in.pixels.length];
	for (int i = 0; i < pixels.length; i += 1) {
		pixels[i] = in.pixels[i] & 0xFF;
	}
	WritableRaster raster = Raster.createWritableRaster(res.getSampleModel(), null);
	raster.setPixels(0, 0, in.width, in.height, pixels);
	res.setData(raster);
	res.flush();
	return res;

}
 
开发者ID:rekit-group,项目名称:rekit-game,代码行数:24,代码来源:ImageManagement.java

示例2: getImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public BufferedImage getImage()
{

	ByteBuffer buffer = this.getImageBytes();

	if (buffer == null)
	{
		LOG.error("Images bytes buffer is null!");
		return null;
	}

	byte[] bytes = new byte[this.size.width * this.size.height * 3];
	byte[][] data = new byte[][] { bytes };

	buffer.get(bytes);

	DataBufferByte dbuf = new DataBufferByte(data, bytes.length, OFFSET);
	WritableRaster raster = Raster.createWritableRaster(this.smodel, dbuf, null);

	BufferedImage bi = new BufferedImage(this.cmodel, raster, false, null);
	bi.flush();

	return bi;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:26,代码来源:WebcamDefaultDevice.java

示例3: getPreferredSize

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public Dimension getPreferredSize(PaintContext context)
{
  Dimension size = null;

  // Get a shared buffer to use for measuring
  BufferedImage buffer = _createOffscreenBuffer(context, 1, 1);

  if (buffer != null)
  {
    Graphics g = _getInitializedGraphics(context, buffer);
    size = super.getPreferredSize(new ProxyContext(context, g));

    // Clean up
    g.dispose();
    buffer.flush();
  }
  else
  {
    // If we didn't get a buffer, just paint the contents directly
    size = super.getPreferredSize(context);
  }

  return size;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:OffscreenWrappingPainter.java

示例4: parseBufferedImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static byte[] parseBufferedImage(BufferedImage image) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    for(int y = 0; y < image.getHeight(); ++y) {
        for(int x = 0; x < image.getWidth(); ++x) {
            Color color = new Color(image.getRGB(x, y), true);
            outputStream.write(color.getRed());
            outputStream.write(color.getGreen());
            outputStream.write(color.getBlue());
            outputStream.write(color.getAlpha());
        }
    }

    image.flush();
    return outputStream.toByteArray();
}
 
开发者ID:WetABQ,项目名称:Nukkit-AntiCheat,代码行数:17,代码来源:AntiAutoAim.java

示例5: parseBufferedImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void parseBufferedImage(BufferedImage image) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            Color color = new Color(image.getRGB(x, y), true);
            outputStream.write(color.getRed());
            outputStream.write(color.getGreen());
            outputStream.write(color.getBlue());
            outputStream.write(color.getAlpha());
        }
    }
    image.flush();
    this.setData(outputStream.toByteArray());
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:Skin.java

示例6: parseBufferedImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public void parseBufferedImage(BufferedImage image) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            Color color = new Color(image.getRGB(x, y), true);
            outputStream.write(color.getRed());
            outputStream.write(color.getGreen());
            outputStream.write(color.getBlue());
            outputStream.write(color.getAlpha());
        }
    }
    image.flush();
    this.setSkinData(outputStream.toByteArray());
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:15,代码来源:Skin.java

示例7: print

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public void print(Graphics g) {

    Component comp = (Component)target;

    // To conserve memory usage, we will band the image.

    int totalW = comp.getWidth();
    int totalH = comp.getHeight();

    int hInc = (int)(totalH / BANDING_DIVISOR);
    if (hInc == 0) {
        hInc = totalH;
    }

    for (int startY = 0; startY < totalH; startY += hInc) {
        int endY = startY + hInc - 1;
        if (endY >= totalH) {
            endY = totalH - 1;
        }
        int h = endY - startY + 1;

        Color bgColor = comp.getBackground();
        int[] pix = createPrintedPixels(0, startY, totalW, h,
                                        bgColor == null ? 255 : bgColor.getAlpha());
        if (pix != null) {
            BufferedImage bim = new BufferedImage(totalW, h,
                                          BufferedImage.TYPE_INT_ARGB);
            bim.setRGB(0, 0, totalW, h, pix, 0, totalW);
            g.drawImage(bim, 0, startY, null);
            bim.flush();
        }
    }

    comp.print(g);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:WComponentPeer.java

示例8: main

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static void main(String []s)
{
    Frame frame = new Frame();
    frame.setVisible(true);

    BufferedImage img = new BufferedImage(frame.getWidth(),
                                          frame.getHeight(),
                                          BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();

    frame.printAll(g);

    g.dispose();
    img.flush();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:PrintAllXcheckJNI.java

示例9: out

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@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) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}
     }

 }
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:37,代码来源:GifCaptcha.java

示例10: transform

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public BufferedImage transform(BufferedImage image)
{
	image = GRAY.filter(image, null);
	Graphics2D graphics = image.createGraphics();
	Font font = new Font("ARIAL", Font.PLAIN, 11);
	if (privacyMode)
	{
		graphics.setColor(Color.DARK_GRAY);
		graphics.fillRect(0, 0, 320, 240);
	}
	graphics.setFont(font);
	graphics.setColor(Color.BLACK);
	graphics.fillRect(0, 0, 320, 20);
	graphics.setColor(Color.WHITE);
	long now = System.currentTimeMillis();
	String str = CommonUtils.convertTimestamp(now);
	if (NMOStatistics.INSTANCE.scheduleStartedOn != 0)
	{
		str = str + "   " + FormattingHelper.formatTimeElapsedWithDays(NMOStatistics.INSTANCE.scheduleStartedOn == 0 ? 0 : now, NMOStatistics.INSTANCE.scheduleStartedOn) + "   " + FormattingHelper.formatTimeElapsedWithDays(NMOStatistics.INSTANCE.scheduleStartedOn == 0 ? 0 : now, NMOStatistics.INSTANCE.scheduleLastOversleep);
	}
	graphics.drawString(str, 4, 14);
	if (MainDialog.isCurrentlyPaused.get() && !((MainDialog.scheduleStatusShort.startsWith("CORE ") || MainDialog.scheduleStatusShort.startsWith("NAP ") || MainDialog.scheduleStatusShort.startsWith("SIESTA ")) && MainDialog.pauseReason.startsWith("Sleep block: ")))
	{
		graphics.setColor(Color.BLACK);
		graphics.fillRect(0, 204, 320, 36);
		graphics.setColor(Color.WHITE);
		graphics.drawString("PAUSED for \"" + MainDialog.pauseReason + "\"\n", 4, 218);
		graphics.drawString("until " + CommonUtils.dateFormatter.format(MainDialog.pausedUntil), 4, 234);
	}
	else
	{
		graphics.setColor(Color.BLACK);
		graphics.fillRect(0, 220, 320, 20);
		graphics.setColor(Color.WHITE);
		graphics.drawString(MainDialog.scheduleStatus, 4, 234);
	}
	image.flush();
	graphics.dispose();
	return image;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:42,代码来源:WebcamCapture.java

示例11: renderImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
  * Render the image given the Map of
  * properties that describe what to render.  A PaintContext
  * object is created using the given Map of properties.
  */
@Override
public Image renderImage(
  ImageContext imageContext,
  Map<Object, Object> requestedProperties,
  Map<Object, Object> responseProperties
  )
{
    if (!isRenderable(imageContext, requestedProperties))
    {
      return null;
    }

    Painter painter = getPainter(imageContext, requestedProperties);

    // First we measure the preferred size using a dummy image of
    // size 1x1 - we need this image to get the Graphics obejct
    // for measuring.
    BufferedImage measureImage = createImage(1, 1);

    // Create a PaintContext to use for measuring
    PaintContext measureContext = createPaintContext(imageContext,
                                                     measureImage,
                                                     requestedProperties,
                                                     responseProperties);

    // Get a measurement for the requested image
    Dimension d = painter.getPreferredSize(measureContext);

    int width = d.width;
    int height = d.height;

    // We're done with the measure image and context - free them up
    measureImage.flush();
    disposePaintContext(measureContext);

    // Now that we know how big the image should be, create the image
    // that we'll use for painting
    BufferedImage paintImage = createImage(width, height);

    // Create a PaintContext to use for drawing
    PaintContext paintContext = createPaintContext(imageContext,
                                                   paintImage,
                                                   requestedProperties,
                                                   responseProperties);

    // Fill in the image with the surrounding color
    Graphics g = paintContext.getPaintGraphics();
    Color oldColor = g.getColor();
    g.setColor(paintContext.getSurroundingColor());
    g.fillRect(0, 0, width, height);
    g.setColor(oldColor);

    // Paint the image
    painter.paint(paintContext, g, 0, 0, width, height);

    // Now that we are done painting, dispose the PaintContext
    disposePaintContext(paintContext);

    // Store width/height for client
    responseProperties.put(WIDTH_RESPONSE_KEY,
                           width);
    responseProperties.put(HEIGHT_RESPONSE_KEY,
                           height);

    return paintImage;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:72,代码来源:PainterImageRenderer.java

示例12: paint

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@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();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:79,代码来源:OffscreenWrappingPainter.java

示例13: __getDialogPadding

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
static ImmInsets __getDialogPadding()
{
  if (_sDialogPadding != null)
    return _sDialogPadding;

  // Create a BufferedImage that we can use to rasterize some glyphs.
  int width = 40;
  int height = 40;
  BufferedImage image = new BufferedImage(40,
                                          40,
                                          BufferedImage.TYPE_INT_ARGB);

  // Get the Graphics object to use to draw into the image
  Graphics g = image.getGraphics();

  // Clear out the image
  g.setColor(Color.white);
  g.fillRect(0, 0, width, height);

  // Render our glyphs
  g.setColor(Color.black);
  g.setFont(new Font("Dialog", Font.PLAIN, 12));

  FontMetrics metrics = g.getFontMetrics();
  int baseline = metrics.getAscent();

  g.drawString("X", 0, baseline);

  // Now that we have rendered the glyphs, we examine the
  // image to see how many lines of padding we've got.
  int top = 0;
  for (int y = 0; y < height; y++)
  {
    if (!_isWhiteScanline(image, y, width))
    {
      top = y;
      break;
    }
  }

  // Just use the descent as the bottom padding
  int bottom = metrics.getDescent();

  _sDialogPadding = new ImmInsets(top, 0, bottom, 0);


  // Clean up
  g.dispose();
  image.flush();

  return _sDialogPadding;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:53,代码来源:BlafImageUtils.java

示例14: getCover

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Gets the icon attribute of the YassGroups object
 *
 * @param s Description of the Parameter
 * @return The icon value
 */
public ImageIcon getCover(String s) {
    //System.out.println("getcover " + s);
    ImageIcon ii = covers.get(s);
    if (ii != null) {
        return ii;
    }

    try {
        s = s.replace(':', '_');
        s = s.replace('?', '_');
        s = s.replace('/', '_');
        s = s.replace('\\', '_');
        s = s.replace('*', '_');
        s = s.replace('\"', '_');
        s = s.replace('<', '_');
        s = s.replace('>', '_');
        s = s.replace('|', '_');

        String coverDir = prop.getProperty("cover-directory");

        File file = new File(coverDir + File.separator + s + ".jpg");
        BufferedImage img;
        if (file.exists()) {
            img = javax.imageio.ImageIO.read(file);
        } else {
            java.net.URL is = I18.getResource(s + ".jpg");
            // throws exception when not found
            img = YassUtils.readImage(is);
        }

        //attention: scale down only
        BufferedImage bufferedImage = YassUtils.getScaledInstance(img, WIDTH, WIDTH);

        //BufferedImage bufferedImage = new BufferedImage(WIDTH, WIDTH, BufferedImage.TYPE_INT_RGB);
        //Graphics2D g2d = bufferedImage.createGraphics();
        //g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        //g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        //g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        //g2d.drawImage(img, 0, 0, WIDTH, WIDTH, null);
        //g2d.dispose();
        img.flush();

        ii = new ImageIcon(bufferedImage);
        covers.put(s, ii);
        return ii;
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return null;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:58,代码来源:YassGroups.java


注:本文中的java.awt.image.BufferedImage.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。