Beispiel #1
0
  public void testRotatingImagesWithDifferentDepths() {
    Image result1 = null, result2 = null, result3 = null, result4 = null;
    Image img1 =
        ImageDescriptor.createFromFile(getClass(), "icons/bits1.bmp").createImage(); // $NON-NLS-1$
    Image img2 =
        ImageDescriptor.createFromFile(getClass(), "icons/bits4.bmp").createImage(); // $NON-NLS-1$;
    Image img3 =
        ImageDescriptor.createFromFile(getClass(), "icons/bits8.gif").createImage(); // $NON-NLS-1$;
    Image img4 =
        ImageDescriptor.createFromFile(getClass(), "icons/bits24.jpg")
            .createImage(); //$NON-NLS-1$;

    try {
      result1 = ImageUtilities.createRotatedImage(img1);
      result2 = ImageUtilities.createRotatedImage(img2);
      result3 = ImageUtilities.createRotatedImage(img3);
      result4 = ImageUtilities.createRotatedImage(img4);
    } catch (Throwable error) {
      fail(error.toString() + "\n" + error.getStackTrace()[0]); // $NON-NLS-1$
    } finally {
      img1.dispose();
      img2.dispose();
      img3.dispose();
      img4.dispose();
      if (result1 != null && !result1.isDisposed()) result1.dispose();
      if (result2 != null && !result2.isDisposed()) result2.dispose();
      if (result3 != null && !result3.isDisposed()) result3.dispose();
      if (result4 != null && !result4.isDisposed()) result4.dispose();
    }
  }
Beispiel #2
0
  public void testImageRotation() {
    Image result1 = null, result2 = null, result3 = null;
    Image img1 = new Image(null, 80, 80);
    Image img2 = new Image(null, 801, 69);
    Image img3 = new Image(null, 501, 799);

    try {
      result1 = ImageUtilities.createRotatedImage(img1);
      result2 = ImageUtilities.createRotatedImage(img2);
      result3 = ImageUtilities.createRotatedImage(img3);
    } catch (Throwable error) {
      fail(error.getMessage() + "\n" + error.getStackTrace()); // $NON-NLS-1$
    } finally {
      img1.dispose();
      img2.dispose();
      img3.dispose();
      if (result1 != null && !result1.isDisposed()) result1.dispose();
      if (result2 != null && !result2.isDisposed()) result2.dispose();
      if (result3 != null && !result3.isDisposed()) result3.dispose();
    }
  }
  public static Image process(String id, String overlayIcon, String baseIcon) {

    Image baseImage = new Image(Display.getCurrent(), baseIcon);
    Image overlayImage = new Image(Display.getCurrent(), overlayIcon);

    int baseWidth = baseImage.getBounds().width;
    int baseHeight = baseImage.getBounds().height;
    int overlayWidth = overlayImage.getBounds().width;
    int overlayHeight = overlayImage.getBounds().height;

    if (id.equals(Icon.BASE_ICON)) {
      return baseImage;
    }

    if (id.equals(Icon.CENTERED_OVERLAY_ICON)) {
      int x = (baseWidth / 2) - (overlayWidth / 2);
      int y = (baseHeight / 2) - (overlayHeight / 2);
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }

    if (id.equals(Icon.TOP_LEFT_CORNER_OVERLAY_ICON)) {
      int x = 0;
      int y = 0;
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }
    if (id.equals(Icon.TOP_RIGHT_CORNER_OVERLAY_ICON)) {
      int x = baseWidth - overlayWidth;
      int y = 0;
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }
    if (id.equals(Icon.BOTTOM_RIGHT_CORNER_OVERLAY_ICON)) {
      int x = baseWidth - overlayWidth;
      int y = baseHeight - overlayHeight;
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }
    if (id.equals(Icon.BOTTOM_LEFT_CORNER_OVERLAY_ICON)) {
      int x = 0;
      int y = baseHeight - overlayHeight;
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }

    if (id.equals(Icon.TOP_SIDE_OVERLAY_ICON)) {
      int x = (baseWidth / 2) - (overlayWidth / 2);
      int y = 0;
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }
    if (id.equals(Icon.RIGHT_SIDE_OVERLAY_ICON)) {
      int x = baseWidth - overlayWidth;
      int y = (baseHeight / 2) - (overlayHeight / 2);
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }
    if (id.equals(Icon.BOTTOM_SIDE_OVERLAY_ICON)) {
      int x = (baseWidth / 2) - (overlayWidth / 2);
      int y = baseHeight - overlayHeight;
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }
    if (id.equals(Icon.LEFT_SIDE_OVERLAY_ICON)) {
      int x = 0;
      int y = (baseHeight / 2) - (overlayHeight / 2);
      return Utils.createOverlapedImage(overlayImage, baseImage, new Point(x, y));
    }

    if (id.equals(Icon.ROTATE_LEFT_BASE_ICON)) {
      return new Image(
          baseImage.getDevice(), Utils.rotateOrFlip(baseImage, SWT.LEFT).getImageData());
    }
    if (id.equals(Icon.ROTATE_RIGHT_BASE_ICON)) {
      return new Image(
          baseImage.getDevice(), Utils.rotateOrFlip(baseImage, SWT.RIGHT).getImageData());
    }
    if (id.equals(Icon.ROTATE_180_BASE_ICON)) {
      return new Image(
          baseImage.getDevice(), Utils.rotateOrFlip(baseImage, SWT.DOWN).getImageData());
    }
    if (id.equals(Icon.FLIP_HORIZONTAL_BASE_ICON)) {
      return new Image(
          baseImage.getDevice(), Utils.rotateOrFlip(baseImage, SWT.HORIZONTAL).getImageData());
    }
    if (id.equals(Icon.FLIP_VERTICAL_BASE_ICON)) {
      return new Image(
          baseImage.getDevice(), Utils.rotateOrFlip(baseImage, SWT.VERTICAL).getImageData());
    }
    if (id.equals(Icon.COLOR_DISABLED)) {
      return new Image(baseImage.getDevice(), baseImage, SWT.IMAGE_DISABLE);
    }
    if (id.equals(Icon.COLOR_GRAY)) {
      return new Image(baseImage.getDevice(), baseImage, SWT.IMAGE_GRAY);
    }
    if (id.contains(Icon.COLOR_RGB)) {
      // input example COLOR_RGB255,0,0
      String[] rgb = id.substring(Icon.COLOR_RGB.length()).split(",");
      return new Image(
          baseImage.getDevice(),
          ImageUtilities.createShadedImage(
              baseImage,
              new Color(
                  baseImage.getDevice(), Integer.parseInt(rgb[0]),
                  Integer.parseInt(rgb[1]), Integer.parseInt(rgb[2]))));
    }
    if (id.equals(Icon.SCALE_16X16)) {
      return new Image(
          baseImage.getDevice(), Utils.scaleImage(baseImage.getImageData(), 16, 16, true));
    }
    if (id.equals(Icon.SCALE_200)) {
      return new Image(baseImage.getDevice(), Utils.scaleImage(baseImage.getImageData(), 2));
    }
    if (id.equals(Icon.SCALE_75)) {
      return new Image(baseImage.getDevice(), Utils.scaleImage(baseImage.getImageData(), 0.75));
    }
    if (id.equals(Icon.SCALE_60)) {
      return new Image(baseImage.getDevice(), Utils.scaleImage(baseImage.getImageData(), 0.6));
    }
    if (id.equals(Icon.SCALE_50)) {
      return new Image(baseImage.getDevice(), Utils.scaleImage(baseImage.getImageData(), 0.5));
    }
    if (id.equals(Icon.SCALE_40)) {
      return new Image(baseImage.getDevice(), Utils.scaleImage(baseImage.getImageData(), 0.4));
    } else {
      return Activator.getImageDescriptor("icons/default/base.png").createImage();
    }
  }