Ejemplo n.º 1
0
  private BufferedImage cropScaleGrayscale(Rectangle visibleRect, RenderedImage image) {
    int minX = image.getMinX();
    int minY = image.getMinY();
    int width = image.getWidth();
    int height = image.getHeight();

    Rectangle bounds = new Rectangle(minX, minY, width, height);

    visibleRect = bounds.intersection(visibleRect);

    if (bounds.contains(visibleRect)) {
      ParameterBlock pb = new ParameterBlock();
      pb.addSource(image);
      pb.add((float) visibleRect.x);
      pb.add((float) visibleRect.y);
      pb.add((float) visibleRect.width);
      pb.add((float) visibleRect.height);
      image = JAI.create("Crop", pb, JAIContext.noCacheHint);
    }
    Dimension previewSize = getSize();

    if ((visibleRect.width > previewSize.width) || (visibleRect.height > previewSize.height)) {
      float scale =
          Math.min(
              previewSize.width / (float) visibleRect.width,
              previewSize.height / (float) visibleRect.height);

      image = ConvolveDescriptor.create(image, Functions.getGaussKernel(.25 / scale), null);
      ParameterBlock pb = new ParameterBlock();
      pb.addSource(image);
      pb.add(scale);
      pb.add(scale);
      image = JAI.create("Scale", pb, JAIContext.noCacheHint);
    }
    image = Functions.toColorSpace(image, JAIContext.systemColorSpace, null);

    if (image.getSampleModel().getDataType() == DataBuffer.TYPE_USHORT) {
      image = Functions.fromUShortToByte(image, null);
    }
    return Functions.toFastBufferedImage(image);
  }
Ejemplo n.º 2
0
  @Override
  public ScreenImage capture(Rectangle rect) {
    Debug.log(5, "capture: " + rect);

    BufferedImage ret = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = ret.createGraphics();
    for (int i = 0; i < Screen.getNumberScreens(); i++) {
      Rectangle scrBound = Screen.getBounds(i);
      if (scrBound.intersects(rect)) {
        Rectangle inter = scrBound.intersection(rect);
        Debug.log(5, "scrBound: " + scrBound + ", inter: " + inter);
        int ix = inter.x, iy = inter.y;
        inter.x -= scrBound.x;
        inter.y -= scrBound.y;
        ScreenImage img = robots[i].captureScreen(inter);
        g2d.drawImage(img.getImage(), ix - rect.x, iy - rect.y, null);
      }
    }
    g2d.dispose();
    return new ScreenImage(rect, ret);
  }