Exemplo n.º 1
0
  public static Image createThumbnail(Image image, int width, int height) {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();

    if ((width > sourceWidth) && (height > sourceHeight)) {
      return image;
    }
    int thumbWidth = width;
    int thumbHeight = thumbWidth * sourceHeight / sourceWidth;
    if (thumbHeight > height) {
      thumbHeight = height;
      thumbWidth = thumbHeight * sourceWidth / sourceHeight;
    }
    // #sijapp cond.if modules_ANDROID is "true"#
    Image scaled = image.scale(thumbWidth, thumbHeight);
    if (null != scaled) return scaled;
    // #sijapp cond.end#

    Image thumb = Image.createImage(thumbWidth, thumbHeight);
    Graphics g = thumb.getGraphics();

    for (int y = 0; y < thumbHeight; ++y) {
      for (int x = 0; x < thumbWidth; ++x) {
        g.setClip(x, y, 1, 1);
        int dx = x * sourceWidth / thumbWidth;
        int dy = y * sourceHeight / thumbHeight;
        g.drawImage(image, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
      }
    }
    return thumb;
  }
Exemplo n.º 2
0
 // #sijapp cond.if protocols_VK is "true" #
 public final Icon getPhoto() {
   Image avatar = getAvatar();
   return new Icon(avatar, 0, 0, avatar.getWidth(), avatar.getHeight());
 }