Class image

java.lang.Object
fr.formiko.usuel.images.image

public class image extends Object
image class that contain a lot of tools to use images.
Author:
Hydrolien
  • Constructor Details

    • image

      public image()
  • Method Details

    • getREPTEXTUREPACK

      public static String getREPTEXTUREPACK()
      The Images directory for extra texture.
      You can add new image that will be used as the game texture (as chargement(Max+1)). Or You can replace some images by puting an image with the same name than an actual image in getREP() or REP_TEMPORARY.
    • setREPTEXTUREPACK

      public static void setREPTEXTUREPACK(String s)
    • getREP

      public static String getREP()
      The Images directory.
    • getREPTEMPORARY

      public static String getREPTEMPORARY()
    • readImage

      public static BufferedImage readImage(File f)
      Try to read an Image file
      Image are File who end with ".png" or ".jpg".
      Parameters:
      f - File that sould contain the Image.
      Returns:
      Image on the file or null if something went wrong.
    • readImage

      public static BufferedImage readImage(String s)
    • getImage

      public static BufferedImage getImage(String nom, boolean returnImageNull)
      get an Image in 1 of the 3 usuals images directories.
      It will 1a search on getREPTEXTUREPACK(), then in getREP() and finaly in REP_TEMPORARY. Image are File who end with ".png" or ".jpg".
      .png or .jpg do not need to be precised on the name.
      Parameters:
      nom - Name of the file without getREP() part.
      returnImageNull - If true it will return an error image insted of null.
    • getImage

      public static BufferedImage getImage(String nom)
    • getImage

      public static BufferedImage getImage(String nom, String repTemp)
      get an Image in a directory.
      Image are File who end with ".png" or ".jpg".
      .png or .jpg do not need to be precised on the name.
      Parameters:
      nom - Name of the file without getREP() part.
      repTemp - directory were to search.
    • getImages

      public static BufferedImage[] getImages(String nom, char lettre, int nbr, byte k)
      get an array [] of Image.
      Image are File who end with ".png" or ".jpg"
      Parameters:
      nom - Name of the file without getREP() part and number and .png or .jpg part of it.
      nbr - Number of image that we want.
      lettre - A letter that can be after the number on rotated image file. ' ' or 'ø' if there is no letter after the number.
      k - Needed only if k!=0. k is the 1a number of the numbering.
    • getImages

      public static BufferedImage[] getImages(String nom, int nbr, byte x)
    • getImages

      public static BufferedImage[] getImages(String nom, byte x)
    • getNbrImages

      public static int getNbrImages(String nom, byte x)
      Fined the last existing number of image from x.
      Image are File who end with ".png" or ".jpg"
      Parameters:
      nom - Name of the file without getREP() part and number and .png or .jpg part of it.
      x - Needed only if x!=0. x is the 1a number of the numbering.
    • getNbrImages

      public static int getNbrImages(String n)
    • getNbrImages

      public static int getNbrImages(String nom, String repStable, byte x)
      Fined the last existing number of image from x on a directory
      Image are File who end with ".png" or ".jpg"
      Parameters:
      nom - Name of the file without repStable part and number and .png or .jpg part of it.
      repStable - Directory name.
      x - Needed only if x!=0. x is the 1a number of the numbering.
    • getNbrImages

      public static int getNbrImages(String n, String repStable)
    • getImages

      public static BufferedImage[] getImages(String nom, int nbr)
    • getImages

      public static BufferedImage[] getImages(String nom)
    • getImagess

      public static BufferedImage[][] getImagess(String nom, int nbr, byte x)
      get an array [][] of Image.
      Image are File who end with ".png" or ".jpg"
      This metode will always return a new Image [4][nbr] to have the 4 rotated images.
      Parameters:
      nom - Name of the file without getREP() part and number and .png or .jpg part of it.
      nbr - Number of image that we want.
      x - Needed only if x!=0. x is the 1a number of the numbering.
    • getImagess

      public static BufferedImage[][] getImagess(String nom, int nbr)
    • getImagess

      public static BufferedImage[][] getImagess(String nom)
    • getImagess

      public static BufferedImage[][] getImagess(String nom, byte x)
    • getScaledInstance

      public static BufferedImage[] getScaledInstance(BufferedImage[] img, int width, int height, int hints)
      transforme to Scaled instance a Image []
      Parameters:
      width - the width to which to scale the image.
      height - the height to which to scale the image.
      hints - flags to indicate the type of algorithm to use for image resampling.
    • clearTemporaire

      public static void clearTemporaire()
      delete every file in REP_TEMPORARY.
    • clearPartielTemporaire

      public static void clearPartielTemporaire()
      delete every FSomething file in REP_TEMPORARY.
    • tailleFourmi

      public static int tailleFourmi(int idEspece, int typeF, int taille)
      Return size of a Creature image.
      If ant is not found it will just return taille.
      Parameters:
      idEspece - id of the Species (size depend of Species)
      typeF - typeF also infulence size of the Ant
      taille - taille used if it was 0% realistic return Size with a part of realistic
    • taille

      public static int taille(int idEspece, int stade, int taille)
      Return size of a Creature image.
      Parameters:
      idEspece - id of the Species (size depend of Species)
      stade - stade also infulence size of the Creature
      taille - taille used if it was 0% realistic
    • taille

      public static int taille(int a, int taille)
      Return size of a Creature image.
      Parameters:
      a - size assumed if it was 100% realistic
      taille - size used if it was 0% realistic
    • isImage

      public static boolean isImage(File f)
      True is file is an Image.
      An image end with .png or .jpg
    • resize

      public static BufferedImage resize(BufferedImage bi, int newW, int newH)
      A fonction to getScaledInstance and return a BufferedImage.
      If images is alredy resize to the exacte dimention it only return the same image.
      cf https://stackoverflow.com/questions/9417356/bufferedimage-resize/9417836#9417836
      Parameters:
      bi - The Image to resize.
      newW - The new width.
      newH - The new height.
    • resize

      public static BufferedImage resize(BufferedImage in, int newHW)
      A fonction to getScaledInstance and return a BufferedImage.
      This function use resize(bufferedImage, width, height).
      This function resize the biger side to newHW & the other size to keep the proportions.
      Parameters:
      in - The Image to resize.
      newHW - The new height or width (biger side).
    • rotateAndCenterImage

      public static BufferedImage rotateAndCenterImage(BufferedImage bi, int direction)
      A fonction to rotate & center a BufferedImage.
      Parameters:
      bi - The Image to rotate & center
      direction - The direction to rotate. Direction are multiplied by 45°
    • trimTransparentBorder

      public static BufferedImage trimTransparentBorder(BufferedImage in)
      A fonction to trim a BufferedImage.
      This function use countTransparentBorders(bufferedImage).
      Parameters:
      in - The Image to trim
    • countTransparentBorders

      public static int[] countTransparentBorders(BufferedImage in)
      A fonction to count transparent borders of a BufferedImage.
      A border is transparent if alpha=0 on all the pixel line.
      Parameters:
      in - The Image to count transparent borders
    • countTransparentBorder

      public static int countTransparentBorder(BufferedImage in, int lenI, int lenJ, boolean revers, boolean fromTheEnd)
      A fonction to count a transparent border of a BufferedImage.
      A border is transparent if alpha=0 on all the pixel line.
      Parameters:
      in - The Image to count transparent borders
      lenI - width or height depending of revers
      lenJ - width or height depending of revers
      revers - True: revers width & height
      fromTheEnd - True: start from the end of the image (width or height)
    • rotateImage

      public static BufferedImage rotateImage(BufferedImage before, int direction)
      A fonction to rotate a BufferedImage.
      Parameters:
      before - The Image to rotate
      direction - The direction to rotate. Direction are multiplied by 45°
    • rotateImage

      public static BufferedImage rotateImage(BufferedImage before, double angle)
      A fonction to rotate a BufferedImage.
      Parameters:
      before - The Image to rotate
      angle - The angle to rotate
    • translateImage

      public static BufferedImage translateImage(BufferedImage before, int xOffset, int yOffset, int width, int height)
      A fonction to translate a BufferedImage.
      Parameters:
      before - The Image to translate.
      xOffset - offset in x.
      yOffset - offset in y.
    • rotateImage2

      public static BufferedImage rotateImage2(BufferedImage before, int direction, int pivotX, int pivotY)
      A fonction to rotate a BufferedImage.
      Parameters:
      before - The Image to rotate.
      direction - The direction to rotate. Direction are multiplied by 1°.
    • flipImage

      public static BufferedImage flipImage(BufferedImage before, boolean vertically)
      A tool to flip a BufferedImage.
      Parameters:
      before - The Image to flip.
      vertically - True, the image will be flip vertically, false it will be flip horizontally.
    • changeColor

      public static BufferedImage changeColor(Img imgColor, Pheromone ph)
      Change the image color depending of ant Pheromone.
      Parameters:
      imgColor - the image to change.
      ph - the Pheromone to get color from.
    • fullOf

      public static byte[][] fullOf(int x, int y, byte b)
      Full the color of an array.
    • getImagesAsMap

      public static HashMap<String,​BufferedImage> getImagesAsMap(File folder)
      Return a new HashMap<String, BufferedImage>.
      Parameters:
      folder - folder that contain all images
    • getImagesAsMap

      public static HashMap<String,​BufferedImage> getImagesAsMap(String folderName)
      Return a new HashMap<String, BufferedImage>.
      Parameters:
      folderName - the name of the folder that contain all images
    • getScaledInstanceFromMap

      public static HashMap<String,​BufferedImage> getScaledInstanceFromMap(HashMap<String,​BufferedImage> mapIn, int size)
      Rezise a HashMap<String, BufferedImage>.
      Parameters:
      mapIn - Map that contains images to rezise
    • printBufferedImageColor

      public static void printBufferedImageColor(BufferedImage bi)
      Print a BufferedImage color.
      Parameters:
      bi - the bufferedImage to print.
    • replaceRectColor

      public static void replaceRectColor(BufferedImage bi, Color col, int x, int y, int width, int height)
      Replace a specified rect by given color.
      Parameters:
      bi - the bufferedImage to use
      col - the color to draw
      x - x of the rectangle
      y - y of the rectangle
      width - width of the rectangle
      height - height of the rectangle
    • toBlackAndWhite

      public static BufferedImage toBlackAndWhite(BufferedImage bi)
      Replace color by black & white shade.
      Parameters:
      bi - the bufferedImage to use
    • editAllPixels

      public static void editAllPixels(BufferedImage bi, Function<Integer,​Integer> fct)
      Edit all pixels of a BufferedImage.
      Parameters:
      bi - the bufferedImage to edit
      fct - the function to apply