Example #1
0
 public Image defaultCapture(Control control) {
   Image image = new Image(control.getDisplay(), control.getBounds());
   GC gc = new GC(image);
   try {
     if (control.print(gc)) {
       return image;
     } else {
       image.dispose();
       Rectangle bounds = control.getBounds();
       return getImage(control, bounds.width, bounds.height, true);
     }
   } finally {
     DisposeUtil.dispose(gc);
   }
 }
Example #2
0
  public Image captureImage(Control control) {
    Rectangle rectangle = control.getBounds();
    Display display = control.getDisplay();
    Image image = null;
    if (control instanceof Shell) {
      Shell shell = (Shell) control;
      shell.layout();
      Point parentLocation = control.toDisplay(0, 0);
      image = getImage(control, rectangle.width, rectangle.height, false);

      rectangle.x = parentLocation.x;
      rectangle.y = parentLocation.y;

      GC myImageGC = new GC(image);
      try {
        for (Control child : shell.getChildren()) {
          Rectangle childBounds = child.getBounds();
          // bug of SWT on Win32, child bounds is not correct in the Window is not in the ToolBar
          int x = (rectangle.width - childBounds.width) / 2;
          int y = (rectangle.height - childBounds.height) - x;
          childBounds.x = rectangle.x + x;
          childBounds.y = rectangle.y + y;
          if (!rectangle.intersects(childBounds)) continue; // Child is completely outside parent.

          Image childImage = new Image(display, child.getBounds());
          GC gc = new GC(childImage);
          child.print(gc);
          DisposeUtil.dispose(gc);
          try {
            myImageGC.drawImage(childImage, x, y);
          } finally {
            childImage.dispose();
          }
        }
      } finally {
        myImageGC.dispose();
      }
    } else {
      image = defaultCapture(control);
    }
    return image;
  }
Example #3
0
  /**
   * Get an Image of the page. The Image is build from the Control.
   *
   * @param The IPage for which an Image is requested.
   * @return The Image of the page, or null if no Image can be built.
   */
  public static Image getPageImage(IPage page) {
    Rectangle size;
    Control control = page.getControl();

    size = control.getBounds();
    if (size.width == 0 && size.height == 0) {
      Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
      size = new Rectangle(0, 0, pt.x, pt.y);
    }

    Image image = new Image(control.getDisplay(), size);
    GC gc = new GC(image);

    boolean success = control.print(gc);
    gc.dispose();
    if (!success) {
      image.dispose();
      return null;
    }

    return image;
  }