Package snap.gfx

Class Image

java.lang.Object
snap.gfx.Image
All Implemented Interfaces:
Loadable
Direct Known Subclasses:
J2DImage

public abstract class Image extends Object implements Loadable
Represents an Image, such as JPEG, PNG, GIF, TIFF, BMP.
  • Constructor Details

    • Image

      protected Image()
      Constructor.
  • Method Details

    • getName

      public String getName()
      Returns the name of image (if from URL/file).
    • getSource

      public Object getSource()
      Returns the source.
    • setSource

      protected void setSource(Object aSource)
      Sets the source.
    • getSourceURL

      public WebURL getSourceURL()
      Returns the source URL.
    • getWidth

      public double getWidth()
      Returns the width of given image.
    • getHeight

      public double getHeight()
      Returns the height of given image.
    • getPixWidth

      public int getPixWidth()
      Returns the width of given image in pixels.
    • getPixHeight

      public int getPixHeight()
      Returns the height of given image in pixels.
    • getDPIX

      public double getDPIX()
      Returns the horizontal image DPI.
    • getDPIY

      public double getDPIY()
      Returns the vertical image DPI.
    • hasAlpha

      public boolean hasAlpha()
      Returns whether image has alpha.
    • getNative

      public abstract Object getNative()
      Returns the native object.
    • getWidthImpl

      protected double getWidthImpl()
      Returns the width of given image.
    • getHeightImpl

      protected double getHeightImpl()
      Returns the height of given image.
    • getPixWidthImpl

      protected abstract int getPixWidthImpl()
      Returns the width of given image in pixels.
    • getPixHeightImpl

      protected abstract int getPixHeightImpl()
      Returns the height of given image in pixels.
    • getDPIXImpl

      protected double getDPIXImpl()
      Returns the width of given image.
    • getDPIYImpl

      protected double getDPIYImpl()
      Returns the height of given image.
    • hasAlphaImpl

      protected abstract boolean hasAlphaImpl()
      Returns whether image has alpha.
    • getBytes

      public byte[] getBytes()
      Returns the source bytes.
    • getBytesImpl

      protected byte[] getBytesImpl()
      Returns the source bytes.
    • getType

      public String getType()
      Returns the type of the image bytes provided.
    • isLoaded

      public boolean isLoaded()
      Returns whether image is loaded (might be delayed is source is URL).
      Specified by:
      isLoaded in interface Loadable
    • setLoaded

      public void setLoaded(boolean aValue)
      Sets whether image is loaded.
    • getRGB

      public abstract int getRGB(int aX, int aY)
      Returns an RGB integer for given x, y.
    • getBytesRGB

      public byte[] getBytesRGB()
      Returns the decoded RGB bytes of this image.
    • getBytesRGBA

      public byte[] getBytesRGBA()
      Returns the decoded RGBA bytes of this image.
    • getBytesRGBImpl

      protected abstract byte[] getBytesRGBImpl()
      Returns the decoded RGB bytes of this image.
    • getBytesRGBAImpl

      protected abstract byte[] getBytesRGBAImpl()
      Returns the decoded RGBA bytes of this image.
    • getBytesJPEG

      public abstract byte[] getBytesJPEG()
      Returns the JPEG bytes for image.
    • getBytesPNG

      public abstract byte[] getBytesPNG()
      Returns the PNG bytes for image.
    • getPainter

      public abstract Painter getPainter()
      Returns a painter to mark up image.
    • getImageSet

      public ImageSet getImageSet()
      Returns the image set.
    • setImageSet

      protected void setImageSet(ImageSet anIS)
      Sets the image set.
    • getScale

      public double getScale()
      Returns the image scale.
    • cloneForSizeAndScale

      public Image cloneForSizeAndScale(double aW, double aH, double aScale)
      Returns a copy of this image at new size and scale.
    • getImageScaled

      public Image getImageScaled(double aRatio)
      Returns a new image scaled by given percent.
    • getImageForSize

      public Image getImageForSize(double aW, double aH)
      Returns a new image at given size.
    • getSubimage

      public Image getSubimage(double aX, double aY, double aW, double aH)
      Returns a subimage from rectangle.
    • getFramedImage

      public Image getFramedImage(int aW, int aH, double aX, double aY)
      Returns an image inside a larget image.
    • getSpriteSheetFrames

      public Image getSpriteSheetFrames(int aCount)
      Returns an image with ImageSet for given number of frames (assumes this is horizontal sprite sheet).
    • blur

      public void blur(int aRad, Color aColor)
      Blurs the image by mixing pixels with those around it to given radius.
    • emboss

      public void emboss(double aRadius, double anAzi, double anAlt)
      Embosses the image by mixing pixels with those around it to given radius.
    • addLoadListener

      public void addLoadListener(Runnable aLoadLsnr)
      Adds a load listener (cleared automatically when loaded).
      Specified by:
      addLoadListener in interface Loadable
    • fireLoadListeners

      public void fireLoadListeners()
      Triggers calls to load listeners.
    • toString

      public String toString()
      Standard toString implementation.
      Overrides:
      toString in class Object
    • toStringProps

      public String toStringProps()
      Standard toStringProps implementation.
    • getImageForSource

      public static Image getImageForSource(Object aSource)
      Creates image from source.
    • getImageForBytes

      public static Image getImageForBytes(byte[] theBytes)
      Creates image from bytes.
    • getImageForClassResource

      public static Image getImageForClassResource(Class<?> aClass, String aPath)
      Creates image from class and resource path.
    • getImageForUrlResource

      public static Image getImageForUrlResource(WebURL aBaseURL, String aName)
      Creates image from URL and resource path.
    • getImageForSize

      public static Image getImageForSize(double aWidth, double aHeight, boolean hasAlpha)
      Creates image for width, height and alpha at standard 72 dpi.
    • getImageForSizeAndScale

      public static Image getImageForSizeAndScale(double aWidth, double aHeight, boolean hasAlpha, double aScale)
      Creates image for width, height, alpha and dpi scale (0 = screen dpi, 1 = 72 dpi, 2 = 144 dpi).
    • canRead

      public static boolean canRead(String anExt)
      Returns whether given extension is supported.
    • canRead

      public static boolean canRead(byte[] bytes)
      Returns whether image reader can read the file provided in the byte array.