Package snap.gfx

Class Image

java.lang.Object
snap.gfx.Image
All Implemented Interfaces:
Loadable

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

    • _width

      protected double _width
    • _height

      protected double _height
    • _pixW

      protected int _pixW
    • _pixH

      protected int _pixH
    • _hasAlpha

      protected boolean _hasAlpha
    • _dpiX

      protected int _dpiX
    • _dpiY

      protected int _dpiY
    • _dpiScale

      protected int _dpiScale
  • 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.
    • hasAlpha

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

      public double getDpiX()
      Returns the horizontal image DPI.
    • getDpiY

      public double getDpiY()
      Returns the vertical image DPI.
    • getDpiScale

      public double getDpiScale()
      Returns the image dpi scale (1 = 72 dpi, 2 = Retina/HiDPI).
    • getNative

      public abstract Object getNative()
      Returns the native object.
    • 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.
    • waitForImageLoad

      public void waitForImageLoad()
      Override to wait.
    • 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.
    • cloneForScale

      public Image cloneForScale(double aRatio)
      Returns a copy of this image scaled by given percent.
    • cloneForSize

      public Image cloneForSize(double newW, double newH)
      Returns a copy of this image at new size.
    • cloneForDpiScale

      public Image cloneForDpiScale(double dpiScale)
      Returns a copy of this image at new dpi scale.
    • cloneForSizeAndDpiScale

      public Image cloneForSizeAndDpiScale(double newW, double newH, double dpiScale)
      Returns a copy of this image at new size and dpi scale.
    • cloneForCropRect

      public Image cloneForCropRect(double aX, double aY, double newW, double newH)
      Returns a subimage from rectangle.
    • getFramedImage

      public Image getFramedImage(int aW, int aH, double aX, double aY)
      Returns an image inside a larger 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.
    • getImageForSizeAndDpiScale

      public static Image getImageForSizeAndDpiScale(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.