Package snap.gfx
Class Image
java.lang.Object
snap.gfx.Image
- All Implemented Interfaces:
Loadable
- Direct Known Subclasses:
J2DImage
Represents an Image, such as JPEG, PNG, GIF, TIFF, BMP.
-
Nested Class Summary
Nested classes/interfaces inherited from interface snap.util.Loadable
Loadable.MultiLoadable, Loadable.Support
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addLoadListener
(Runnable aLoadLsnr) Adds a load listener (cleared automatically when loaded).void
Blurs the image by mixing pixels with those around it to given radius.static boolean
canRead
(byte[] bytes) Returns whether image reader can read the file provided in the byte array.static boolean
Returns whether given extension is supported.cloneForSizeAndScale
(double aW, double aH, double aScale) Returns a copy of this image at new size and scale.void
emboss
(double aRadius, double anAzi, double anAlt) Embosses the image by mixing pixels with those around it to given radius.void
Triggers calls to load listeners.byte[]
getBytes()
Returns the source bytes.protected byte[]
Returns the source bytes.abstract byte[]
Returns the JPEG bytes for image.abstract byte[]
Returns the PNG bytes for image.byte[]
Returns the decoded RGB bytes of this image.byte[]
Returns the decoded RGBA bytes of this image.protected abstract byte[]
Returns the decoded RGBA bytes of this image.protected abstract byte[]
Returns the decoded RGB bytes of this image.double
getDPIX()
Returns the horizontal image DPI.protected double
Returns the width of given image.double
getDPIY()
Returns the vertical image DPI.protected double
Returns the height of given image.getFramedImage
(int aW, int aH, double aX, double aY) Returns an image inside a larget image.double
Returns the height of given image.protected double
Returns the height of given image.static Image
getImageForBytes
(byte[] theBytes) Creates image from bytes.static Image
getImageForClassResource
(Class<?> aClass, String aPath) Creates image from class and resource path.getImageForSize
(double aW, double aH) Returns a new image at given size.static Image
getImageForSize
(double aWidth, double aHeight, boolean hasAlpha) Creates image for width, height and alpha at standard 72 dpi.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).static Image
getImageForSource
(Object aSource) Creates image from source.static Image
getImageForUrlResource
(WebURL aBaseURL, String aName) Creates image from URL and resource path.getImageScaled
(double aRatio) Returns a new image scaled by given percent.Returns the image set.getName()
Returns the name of image (if from URL/file).abstract Object
Returns the native object.abstract Painter
Returns a painter to mark up image.int
Returns the height of given image in pixels.protected abstract int
Returns the height of given image in pixels.int
Returns the width of given image in pixels.protected abstract int
Returns the width of given image in pixels.abstract int
getRGB
(int aX, int aY) Returns an RGB integer for given x, y.double
getScale()
Returns the image scale.Returns the source.Returns the source URL.getSpriteSheetFrames
(int aCount) Returns an image with ImageSet for given number of frames (assumes this is horizontal sprite sheet).getSubimage
(double aX, double aY, double aW, double aH) Returns a subimage from rectangle.getType()
Returns the type of the image bytes provided.double
getWidth()
Returns the width of given image.protected double
Returns the width of given image.boolean
hasAlpha()
Returns whether image has alpha.protected abstract boolean
Returns whether image has alpha.boolean
isLoaded()
Returns whether image is loaded (might be delayed is source is URL).protected void
setImageSet
(ImageSet anIS) Sets the image set.void
setLoaded
(boolean aValue) Sets whether image is loaded.protected void
Sets the source.toString()
Standard toString implementation.Standard toStringProps implementation.
-
Constructor Details
-
Image
protected Image()Constructor.
-
-
Method Details
-
getName
Returns the name of image (if from URL/file). -
getSource
Returns the source. -
setSource
Sets the source. -
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
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
Returns the type of the image bytes provided. -
isLoaded
public boolean isLoaded()Returns whether image is loaded (might be delayed is source is URL). -
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
Returns a painter to mark up image. -
getImageSet
Returns the image set. -
setImageSet
Sets the image set. -
getScale
public double getScale()Returns the image scale. -
cloneForSizeAndScale
Returns a copy of this image at new size and scale. -
getImageScaled
Returns a new image scaled by given percent. -
getImageForSize
Returns a new image at given size. -
getSubimage
Returns a subimage from rectangle. -
getFramedImage
Returns an image inside a larget image. -
getSpriteSheetFrames
Returns an image with ImageSet for given number of frames (assumes this is horizontal sprite sheet). -
blur
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
Adds a load listener (cleared automatically when loaded).- Specified by:
addLoadListener
in interfaceLoadable
-
fireLoadListeners
public void fireLoadListeners()Triggers calls to load listeners. -
toString
Standard toString implementation. -
toStringProps
Standard toStringProps implementation. -
getImageForSource
Creates image from source. -
getImageForBytes
Creates image from bytes. -
getImageForClassResource
Creates image from class and resource path. -
getImageForUrlResource
Creates image from URL and resource path. -
getImageForSize
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
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.
-