Esempio n. 1
0
 /**
  * Checks if image should be recolored and resized or only resized.
  *
  * @param img - image
  * @param w - width to set
  * @param h - height to set
  * @param name - file name
  * @return
  */
 public static BufferedImage resetTheImage(BufferedImage img, int w, int h, String name) {
   if (name.contains("dnrc") || name.contains("DNRC")) {
     if (w != 0 && h != 0) {
       return resizeImage(img, w, h);
     } else if (img.getWidth() > Config.getWidth() - 20) {
       return resizeImage(img, Config.getWidth() - 20, Config.getHeight());
     }
   } else {
     return recolorImage(img, w, h);
   }
   return null;
 }
Esempio n. 2
0
  /**
   * This method recolors and resizes image. Recoloring is done using math:
   * r*(frontground_Red/255)...
   */
  public static BufferedImage recolorImage(BufferedImage img, int w, int h) {
    int kolor, red, green, blue;
    BufferedImage out;
    BufferedImage resized = img;

    if (w != 0 && h != 0) {
      out = new BufferedImage(w, h, img.getType());
    } else {
      out = new BufferedImage(Config.getWidth() - 20, Config.getHeight(), img.getType());
    }

    /*
     * Check if the image is too width, else we ignore it.
     */
    if (w != 0 && h != 0) {
      resized = resizeImage(img, w, h);
    } else if (img.getWidth() > Config.getWidth() - 20) {
      resized = resizeImage(img, Config.getWidth() - 20, Config.getHeight());
    }

    Graphics2D g = out.createGraphics();

    for (int x = 0; x < resized.getWidth(); x += getSkipPixels()) {
      for (int y = 0; y < resized.getHeight(); y += getSkipPixels()) {
        kolor = resized.getRGB(x, y);
        red = (kolor & 0x00ff0000) >> 16;
        green = (kolor & 0x0000ff00) >> 8;
        blue = kolor & 0x000000ff;
        g.setColor(transformColor(red, green, blue));
        g.fillRect(x, y, getSkipPixels(), getSkipPixels());
      }
    }
    g.dispose();

    return out;
  }
Esempio n. 3
0
  /**
   * Resizes image to width equal to console width-20 and image height
   *
   * @param img - image to resize
   * @return resized image
   */
  public static BufferedImage resizeImage(BufferedImage img) {
    BufferedImage out =
        new BufferedImage(Config.getWidth() - 20, Config.getHeight(), img.getType());
    Graphics2D g = out.createGraphics();

    g.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(
        img,
        0,
        0,
        Config.getWidth() - 20,
        img.getHeight(),
        0,
        0,
        img.getWidth(),
        img.getHeight(),
        null);
    g.dispose();

    return out;
  }