Package snap.gfx
Class Image
java.lang.Object
snap.gfx.Image
- All Implemented Interfaces:
Loadable
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
-
Field Summary
-
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.cloneForCropRect
(double aX, double aY, double newW, double newH) Returns a subimage from rectangle.cloneForDpiScale
(double dpiScale) Returns a copy of this image at new dpi scale.cloneForScale
(double aRatio) Returns a copy of this image scaled by given percent.cloneForSize
(double newW, double newH) Returns a copy of this image at new size.cloneForSizeAndDpiScale
(double newW, double newH, double dpiScale) Returns a copy of this image at new size and dpi 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
Returns the image dpi scale (1 = 72 dpi, 2 = Retina/HiDPI).double
getDpiX()
Returns the horizontal image DPI.double
getDpiY()
Returns the vertical image DPI.getFramedImage
(int aW, int aH, double aX, double aY) Returns an image inside a larger image.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.static Image
getImageForSize
(double aWidth, double aHeight, boolean hasAlpha) Creates image for width, height and alpha at standard 72 dpi.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).static Image
getImageForSource
(Object aSource) Creates image from source.static Image
getImageForUrlResource
(WebURL aBaseURL, String aName) Creates image from URL and resource path.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.int
Returns the width of given image in pixels.abstract int
getRGB
(int aX, int aY) Returns an RGB integer for given x, y.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).getType()
Returns the type of the image bytes provided.double
getWidth()
Returns the width of given image.boolean
hasAlpha()
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.void
Override to wait.
-
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
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. -
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
Returns the native object. -
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. -
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
Returns a painter to mark up image. -
getImageSet
Returns the image set. -
setImageSet
Sets the image set. -
cloneForScale
Returns a copy of this image scaled by given percent. -
cloneForSize
Returns a copy of this image at new size. -
cloneForDpiScale
Returns a copy of this image at new dpi scale. -
cloneForSizeAndDpiScale
Returns a copy of this image at new size and dpi scale. -
cloneForCropRect
Returns a subimage from rectangle. -
getFramedImage
Returns an image inside a larger 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. -
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
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.
-