Esempio n. 1
0
 /*
  *  Create a BufferedImage for AWT components.
  *
  *  @param	 component AWT component to create image from
  *  @param	 fileName name of file to be created or null
  *  @return	image the image for the given region
  *  @exception AWTException see Robot class constructors
  *  @exception IOException if an error occurs during writing
  */
 public static BufferedImage createImage(Component component, String fileName)
     throws AWTException, IOException {
   Point p = new Point(0, 0);
   SwingUtilities.convertPointToScreen(p, component);
   Rectangle region = component.getBounds();
   region.x = p.x;
   region.y = p.y;
   return ScreenCapture.createImage(region, fileName);
 }
Esempio n. 2
0
  /** Processes the data and renders it to a component */
  public synchronized int process(Buffer buffer) {
    if (component == null) return BUFFER_PROCESSED_FAILED;

    Format inf = buffer.getFormat();
    if (inf == null) return BUFFER_PROCESSED_FAILED;

    if (inf != inputFormat || !buffer.getFormat().equals(inputFormat)) {
      if (setInputFormat(inf) != null) return BUFFER_PROCESSED_FAILED;
    }

    Object data = buffer.getData();
    if (!(data instanceof int[])) return BUFFER_PROCESSED_FAILED;

    if (lastBuffer != buffer) {
      lastBuffer = buffer;
      newImage(buffer);
    }

    sourceImage.newPixels(0, 0, inWidth, inHeight);

    Graphics g = component.getGraphics();
    if (g != null) {
      if (reqBounds == null) {
        bounds = component.getBounds();
        bounds.x = 0;
        bounds.y = 0;
      } else bounds = reqBounds;
      g.drawImage(
          destImage,
          bounds.x,
          bounds.y,
          bounds.width,
          bounds.height,
          0,
          0,
          inWidth,
          inHeight,
          component);
    }

    return BUFFER_PROCESSED_OK;
  }