Class DbImageImpl

java.lang.Object
com.illumon.dbtypes.DbImageImpl
All Implemented Interfaces:
DbFile, DbImage, Externalizable, Serializable

public class DbImageImpl extends Object implements DbImage, Externalizable
An image which can be persisted.
See Also:
  • Constructor Details

    • DbImageImpl

      public DbImageImpl()
      This method is only present to support Externalizable. It should not be used otherwise.
    • DbImageImpl

      public DbImageImpl(byte[] bytes)
      Creates an image from image file bytes.
      Parameters:
      bytes - image file bytes
      Throws:
      NullPointerException - if bytes is null.
    • DbImageImpl

      public DbImageImpl(String file) throws IOException
      Creates an image from an image file.
      Parameters:
      file - file location
      Throws:
      NullPointerException - file is null.
      IOException
    • DbImageImpl

      public DbImageImpl(File file) throws IOException
      Creates an image from an image file.
      Parameters:
      file - file location
      Throws:
      NullPointerException - file is null.
      IOException
    • DbImageImpl

      public DbImageImpl(BufferedImage image)
      Creates an image from a BufferedImage.
      Parameters:
      image - input image
      Throws:
      NullPointerException - image is null.
  • Method Details

    • getName

      public String getName()
      Description copied from interface: DbFile
      Gets the file name.
      Specified by:
      getName in interface DbFile
      Returns:
      file name.
    • getType

      public String getType()
      Description copied from interface: DbFile
      Gets the file type.
      Specified by:
      getType in interface DbFile
      Returns:
      file type.
    • getBytes

      public byte[] getBytes()
      Description copied from interface: DbImage
      Gets the image file content as a byte array.
      Specified by:
      getBytes in interface DbFile
      Specified by:
      getBytes in interface DbImage
      Returns:
      image file content as a byte array.
    • getBufferedImage

      public BufferedImage getBufferedImage()
      Description copied from interface: DbImage
      Gets a BufferedImage representation of this image.
      Specified by:
      getBufferedImage in interface DbImage
      Returns:
      BufferedImage representation of this image.
    • getHeight

      public int getHeight()
      Description copied from interface: DbImage
      Gets the height of the image in pixels.
      Specified by:
      getHeight in interface DbImage
      Returns:
      height of the image in pixels.
    • getWidth

      public int getWidth()
      Description copied from interface: DbImage
      Gets the width of the image in pixels.
      Specified by:
      getWidth in interface DbImage
      Returns:
      width of the image in pixels.
    • getColor

      public Color getColor(int x, int y)
      Description copied from interface: DbImage
      Gets the color of the pixel located at (x,y).
      Specified by:
      getColor in interface DbImage
      Parameters:
      x - x-location in pixels.
      y - y-location in pixels.
      Returns:
      color of the pixel located at (x,y).
    • getRed

      public int getRed(int x, int y)
      Description copied from interface: DbImage
      Gets the red component in the range 0-255 in the default sRGB space for the pixel located at (x,y).
      Specified by:
      getRed in interface DbImage
      Parameters:
      x - x-location in pixels.
      y - y-location in pixels.
      Returns:
      red color component of the pixel located at (x,y).
    • getGreen

      public int getGreen(int x, int y)
      Description copied from interface: DbImage
      Gets the green component in the range 0-255 in the default sRGB space for the pixel located at (x,y).
      Specified by:
      getGreen in interface DbImage
      Parameters:
      x - x-location in pixels.
      y - y-location in pixels.
      Returns:
      green color component of the pixel located at (x,y).
    • getBlue

      public int getBlue(int x, int y)
      Description copied from interface: DbImage
      Gets the blue component in the range 0-255 in the default sRGB space for the pixel located at (x,y).
      Specified by:
      getBlue in interface DbImage
      Parameters:
      x - x-location in pixels.
      y - y-location in pixels.
      Returns:
      blue color component of the pixel located at (x,y).
    • getGray

      public int getGray(int x, int y)
      Description copied from interface: DbImage
      Gets the gray-scale value in the range 0-255 in the default sRGB space for the pixel located at (x,y).
      Specified by:
      getGray in interface DbImage
      Parameters:
      x - x-location in pixels.
      y - y-location in pixels.
      Returns:
      gray-scale value of the pixel located at (x,y).
    • write

      public void write(String file) throws IOException
      Description copied from interface: DbFile
      Writes the file out.
      Specified by:
      write in interface DbFile
      Parameters:
      file - output file name
      Throws:
      IOException - problem writing out the file.
    • write

      public void write(String formatName, String file) throws IOException
      Description copied from interface: DbImage
      Writes the image to file.
      Specified by:
      write in interface DbImage
      Parameters:
      formatName - output format name (e.g. "JPEG")
      file - output file
      Throws:
      IOException - problem writing out the image.
    • subImage

      public DbImageImpl subImage(int x, int y, int w, int h)
      Description copied from interface: DbImage
      Creates a sub-image of this image.
      Specified by:
      subImage in interface DbImage
      Parameters:
      x - the X coordinate of the upper-left corner of the specified rectangular region
      y - the Y coordinate of the upper-left corner of the specified rectangular region
      w - the width of the specified rectangular region
      h - the height of the specified rectangular region
      Returns:
      sub-image
    • resize

      public DbImageImpl resize(int width, int height, DbImage.ImageScalingAlgorithm algo)
      Description copied from interface: DbImage
      Creates a new resized image.
      Specified by:
      resize in interface DbImage
      Parameters:
      width - new image width in pixels.
      height - new image height in pixels.
      algo - algorithm used to rescale the image. null causes the default to be usedl.
      Returns:
      resized image.
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException