コード例 #1
0
  private void setSoldierImage() {
    String bigFilePath =
        Patch.GAME_ROOT
            + "\\alexander\\data\\ui\\unit_info\\"
            + unitFaction
            + "\\"
            + soldierDictionary
            + "_info.tga";
    String smallFilePath =
        Patch.GAME_ROOT
            + "\\alexander\\data\\ui\\units\\"
            + unitFaction
            + "\\#"
            + soldierDictionary
            + ".tga";
    if (soldierImage != null) {
      try {
        TgaLoader.saveImage(new FileOutputStream(bigFilePath), soldierImage.scaledTo(160, 210));

        if (!isSpecialGeneralUnit) {
          if (soldierCardImage != null) {
            TgaLoader.saveImage(
                new FileOutputStream(smallFilePath), soldierCardImage.scaledTo(48, 64));
          } else {
            TgaLoader.saveImage(new FileOutputStream(smallFilePath), soldierImage.scaledTo(48, 64));
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
ファイル: ImageHandler.java プロジェクト: psh24053/weiboSMO
  /**
   * 根据当前的各种条件,获取Image对象
   *
   * @return
   */
  public Image getImage() {
    ImageData data = new ImageData(resPath);

    data.type = this.imageType;
    if (this.imageWidth == 0 && this.imageHeight == 0) {
      data = data.scaledTo((int) (data.width * this.scaling), (int) (data.height * this.scaling));
    } else {
      data = data.scaledTo(imageWidth, imageHeight);
    }

    return new Image(display, data);
  }
コード例 #3
0
  /**
   * Returns a scaled instance of the tile image. Using a MediaTracker instance, this function waits
   * until the scaling operation is done.
   *
   * <p>Internally it caches the scaled image in order to optimize the common case, where the same
   * scale is requested as the last time.
   *
   * @param zoom the requested zoom level
   * @return Image
   */
  public Image getScaledImage(double zoom) {
    if (zoom == 1.0) {
      return getImage();
    } else if (zoom == myZoom && scaledImage != null) {
      return scaledImage;
    } else {
      Image img = getImage();
      Rectangle bounds = img.getBounds();
      if (img != null) {
        ImageData imageData = img.getImageData();
        if (tileset != null && tileset.getTransparentColor() != null) {
          imageData.transparentPixel = imageData.palette.getPixel(tileset.getTransparentColor());
        }
        scaledImage =
            new Image(
                Display.getDefault(),
                imageData.scaledTo(
                    (int) Math.round(bounds.width * zoom), (int) Math.round(bounds.height * zoom)));

        //                MediaTracker mediaTracker = new MediaTracker(new Canvas());
        //                mediaTracker.addImage(scaledImage, 0);
        //                try {
        //                    mediaTracker.waitForID(0);
        //                }
        //                catch (InterruptedException ie) {
        //                    System.err.println(ie);
        //                }
        //                mediaTracker.removeImage(scaledImage);
        myZoom = zoom;
        return scaledImage;
      }
    }

    return null;
  }
コード例 #4
0
 /* (non-Javadoc)
  * @see org.nightlabs.eclipse.ui.fckeditor.file.ContentFileBasePage#applySourceFile()
  */
 @Override
 protected void applySourceFile() {
   super.applySourceFile();
   if (getSourceFile() != null && imageLabel != null) {
     imageLabel.setImage(null);
     if (previewImage != null) {
       previewImage.dispose();
       previewImage = null;
     }
     try {
       ImageData id = ImageUtil.loadImage(getSourceFile(), new NullProgressMonitor());
       // ImageData id = new ImageData(new FileInputStream(getSourceFile()));
       float m = Math.max(id.width / 200f, id.height / 200f);
       int width = Math.round(id.width / m);
       int height = Math.round(id.height / m);
       previewImage = new Image(getShell().getDisplay(), id.scaledTo(width, height));
       imageLabel.setImage(previewImage);
       if (!disposeListenerRegistered) {
         getShell().addDisposeListener(this);
         disposeListenerRegistered = true;
       }
     } catch (Exception e) {
       Activator.err("Error loading image preview", e); // $NON-NLS-1$
       previewImage = null;
       imageLabel.setText(
           Messages.getString(
               "org.nightlabs.eclipse.ui.fckeditor.file.image.ContentImageFileBasePage.previewLoadingErrorText")); //$NON-NLS-1$
     }
   }
 }
コード例 #5
0
  public static ImageData resize(
      final Display display,
      final ImageData imageData,
      final int width,
      final int height,
      final boolean antiAliasing) {

    if (imageData == null) {
      return null;
    }

    if (imageData.width == width && imageData.height == height) {
      return imageData;
    }

    if (antiAliasing) {
      Image tmpImage = null;
      final Image fullImage = new Image(display, imageData);
      ImageData result = null;
      tmpImage = resize(display, fullImage, width, height);

      result = tmpImage.getImageData();
      tmpImage.dispose();
      fullImage.dispose();
      return result;
    }
    return imageData.scaledTo(width, height);
  }
コード例 #6
0
  private ImageData createHilbertHeapImage(byte pixData[]) {
    int w, h;

    // Pick an image size that the largest of heaps will fit into.
    w = (int) Math.sqrt(((16 * 1024 * 1024) / 8));

    // Space-filling curves require a power-of-2 width.
    w = nextPow2(w);
    h = w;

    // Create the heap image.
    ImageData id = new ImageData(w, h, 8, mMapPalette);

    // Copy the data into the image
    // int maxX = zOrderData(id, pixData);
    Point maxP = hilbertOrderData(id, pixData);

    // update the max size to make it a round number once the zoom is applied
    int factor = 100 / ZOOMS[mZoom.getSelectionIndex()];
    if (factor != 1) {
      int tmp = maxP.x % factor;
      if (tmp != 0) {
        maxP.x += factor - tmp;
      }

      tmp = maxP.y % factor;
      if (tmp != 0) {
        maxP.y += factor - tmp;
      }
    }

    if (maxP.y < id.height) {
      // Crop the image down to the interesting part.
      id = new ImageData(id.width, maxP.y, id.depth, id.palette, id.scanlinePad, id.data);
    }

    if (maxP.x < id.width) {
      // crop the image again. A bit trickier this time.
      ImageData croppedId = new ImageData(maxP.x, id.height, id.depth, id.palette);

      int[] buffer = new int[maxP.x];
      for (int l = 0; l < id.height; l++) {
        id.getPixels(0, l, maxP.x, buffer, 0);
        croppedId.setPixels(0, l, maxP.x, buffer, 0);
      }

      id = croppedId;
    }

    // apply the zoom
    if (factor != 1) {
      id = id.scaledTo(id.width / factor, id.height / factor);
    }

    return id;
  }
コード例 #7
0
ファイル: ScaledWidgetFactory.java プロジェクト: kthoms/toast
 public Image getSizedImage(String filename, int width, int height) {
   if (filename == null) return null;
   InputStream stream = clazz.getResourceAsStream(filename);
   if (stream == null) throw new RuntimeException(filename + " not found");
   ImageData data = new ImageData(stream);
   if (width != 0 && height != 0 && data.width != width || data.height != height) {
     LogUtility.logDebug("ScaledWidgetFactory", "scaling image for " + filename);
     data = data.scaledTo(width, height);
   }
   return new Image(Display.getCurrent(), data);
 }
コード例 #8
0
ファイル: SkinComposite.java プロジェクト: paulcager/andmore
  /**
   * Loads a new screen image to the currentSkin attribute. This action updates the skin image that
   * is drawn as skin
   *
   * @param imageToSet The new skin pixel data, as retrieved from the skin plugin
   * @param changedKey The key that has changed, if any. If one if provided, only the key area
   *     should be redrawn. Can be <code>null</code>.
   * @param forceDraw true if a draw is needed after setting the new image; false if replacing skin
   *     image only will be performed.
   */
  private void setSkinImage(ImageData imageToSet, IAndroidKey changedKey, boolean forceDraw) {

    recalculateZoomFactor();

    if (imageToSet != null) {
      if (currentSkinImage != null) {
        currentSkinImage.dispose();
      }

      // Scales the chosen image and sets to currentSkin attribute
      //
      // NOTE: width and height cannot be equal to MINIMUM_ZOOM_FACTOR,
      // because this
      // will raise an IllegalArgumentException when constructing the
      // Image object
      int width = (zoomFactor == MINIMUM_ZOOM_FACTOR ? 1 : (int) (imageToSet.width * zoomFactor));
      int height = (zoomFactor == MINIMUM_ZOOM_FACTOR ? 1 : (int) (imageToSet.height * zoomFactor));
      currentSkinImage = new Image(getDisplay(), imageToSet.scaledTo(width, height));

      // It only makes sense to reset the translation if the skin image is
      // really being changed
      // It will happen if we set a image data without specifying a
      // changed key
      if (changedKey == null) {
        displayRectangle.x = 0;
        displayRectangle.y = 0;
      }

      if (forceDraw) {
        layout();

        GC gc = new GC(this);
        drawSkin(gc, changedKey);
        gc.dispose();
      }
    } else {
      info("It was requested to set a skin image that was null. Operation aborted.");
    }
  }
コード例 #9
0
 /**
  * Scale image.
  *
  * @param id the id
  * @param scaleFactor the scale factor
  * @return the image
  */
 public static Image scaleImage(final ImageData id, float scaleFactor) {
   final int w = (int) (id.width * scaleFactor);
   final int h = (int) (id.height * scaleFactor);
   return ResourceManager.getImage(id.scaledTo(w, h));
 }