public class ScaledImage extends Image
Image.scale(int, int)
always makes a scaled copy of the underlying
native image. We use this class ScaledImage to avoid this extensive copying
of pixel arrays in Java, and instead use hardware-accelerated image scaling
when possible. In our implementation, Image.scale(int, int)
returns
an instance of ScaledImage that holds a reference to the unscaled original
image. A copy is created on demand if either the scaled or the unscaled image
gets mutated (copy-on-write idiom). Therefore, a CodenameOne client cannot observe
a behavioral difference between our implementation and the original CodenameOne
implementation (almost ... see deviation below).
Known observable deviations from CodenameOne:
- In CodenameOne, the following assertion is always satisfied. This is not
the case in aicas's implementation.
image.scaled(w,h) instanceof image.getClass()
In aicas's implementation, the following assertion is satisfied instead:
image.scaled(w,h).getClass() == ScaledImage.classModifier | Constructor and Description |
---|---|
protected |
ScaledImage(Image image,
int scaledWidth,
int scaledHeight) |
Modifier and Type | Method and Description |
---|---|
boolean |
animate() |
Image |
applyMask(Object mask)
Applies the given alpha mask onto this image and returns the resulting image
see the createMask method for indication on how to convert an image into an alpha
mask.
|
Image |
applyMask(Object mask,
int x,
int y)
Applies the given alpha mask onto this image and returns the resulting image
see the createMask method for indication on how to convert an image into an alpha
mask.
|
Object |
createMask()
Creates a mask from the given image, a mask can be used to apply an arbitrary
alpha channel to any image.
|
protected void |
drawImage(Graphics g,
Object nativeGraphics,
int x,
int y)
Callback invoked internally by Codename One to draw the image/frame onto the display.
|
protected void |
drawImage(Graphics g,
Object nativeGraphics,
int x,
int y,
int w,
int h)
Callback invoked internally by Codename One to draw the image/frame onto the display.
|
Graphics |
getGraphics()
If this is a mutable image a graphics object allowing us to draw on it
is returned.
|
int |
getHeight()
Returns the height of the image
|
Object |
getImage()
Returns the platform specific image implementation, warning the
implementation class can change between revisions of Codename One and platforms.
|
protected void |
getRGB(int[] rgbData,
int offset,
int scanWidth,
int x,
int y,
int width,
int height)
Obtains ARGB pixel data from the specified region of this image and
stores it in the provided array of integers.
|
Object |
getSVGDocument()
Returns a platform specific DOM object that can be manipulated by the user
to change the SVG Image
|
int |
getWidth()
Returns the width of the image
|
boolean |
isAnimation()
Returns true if this is an animated image
|
boolean |
isOpaque()
Indicates whether this image is opaque or not
|
boolean |
isSVG()
Indicates if this image represents an SVG file or a bitmap file
|
Image |
modifyAlpha(byte alpha)
Creates a new image instance with the alpha channel of opaque/translucent
pixels within the image using the new alpha value.
|
Image |
modifyAlpha(byte alpha,
int removeColor)
Creates a new image instance with the alpha channel of opaque/translucent
pixels within the image using the new alpha value.
|
Image |
modifyAlphaWithTranslucency(byte alpha)
Creates a new image instance with the alpha channel of opaque
pixels within the image using the new alpha value.
|
Image |
rotate(int degrees)
Returns an instance of this image rotated by the given number of degrees.
|
void |
scale(int width,
int height)
Deprecated.
|
Image |
scaled(int width,
int height,
boolean shared)
Similar to
Image.scale(int, int) . |
Image |
subImage(int x,
int y,
int width,
int height,
boolean processAlpha)
Extracts a subimage from the given image allowing us to breakdown a single large image
into multiple smaller images in RAM, this actually creates a standalone version
of the image for use.
|
protected void |
tileRect(Graphics g,
Object nativeGraphics,
int x,
int y,
int rect_width,
int rect_height)
Callback invoked internally by CodenameOne to draw tiles over the image/frame
onto the display.
|
void |
toRGB(RGBImage image,
int destX,
int destY,
int x,
int y,
int width,
int height)
Extracts data from this image into the given RGBImage
|
applyMaskAutoScale, asyncLock, createImage, createImage, createImage, createImage, createImage, createImage, createImage, createIndexed, createSVG, dispose, flipHorizontally, flipVertically, getImageName, getRGB, getRGBCached, isAlphaMutableImageSupported, isLocked, isSVGSupported, lock, mirror, rotate180Degrees, rotate270Degrees, rotate90Degrees, scaled, scaledHeight, scaledLargerRatio, scaledSmallerRatio, scaledWidth, setImageName, unlock
protected ScaledImage(Image image, int scaledWidth, int scaledHeight)
image
- scaledWidth
- scaledHeight
- protected void drawImage(Graphics g, Object nativeGraphics, int x, int y)
Image
protected void drawImage(Graphics g, Object nativeGraphics, int x, int y, int w, int h)
Image
public int getWidth()
Image
public int getHeight()
Image
protected void getRGB(int[] rgbData, int offset, int scanWidth, int x, int y, int width, int height)
Image
getRGB
in class Image
rgbData
- an array of integers in which the ARGB pixel data is
storedoffset
- the index into the array where the first ARGB value is
storedx
- the x-coordinate of the upper left corner of the regiony
- the y-coordinate of the upper left corner of the regionwidth
- the width of the regionheight
- the height of the regionpublic void toRGB(RGBImage image, int destX, int destY, int x, int y, int width, int height)
Image
toRGB
in class Image
image
- RGBImage that would receive pixel datadestX
- x location within RGBImage into which the data will
be writtendestY
- y location within RGBImage into which the data will
be writtenx
- location within the source imagey
- location within the source imagewidth
- size of the image to extract from the source imageheight
- size of the image to extract from the source imagepublic Object getSVGDocument()
Image
getSVGDocument
in class Image
public boolean isSVG()
Image
public Image modifyAlpha(byte alpha)
Image
modifyAlpha
in class Image
alpha
- New value for the entire alpha channelpublic Object createMask()
Image
createMask
in class Image
public Image applyMask(Object mask, int x, int y)
Image
public Image applyMask(Object mask)
Image
public Image subImage(int x, int y, int width, int height, boolean processAlpha)
Image
subImage
in class Image
x
- the x offset from the imagey
- the y offset from the imagewidth
- the width of internal imagesheight
- the height of internal imagesprocessAlpha
- whether alpha should be processed as well as part of the cuttingpublic Image rotate(int degrees)
Image
E.g. rotating an image to 45, 90 and 135 degrees is inefficient. Use rotatate to 45, 90 and then rotate the 45 to another 90 degrees to achieve the same effect with less memory.
public Image modifyAlphaWithTranslucency(byte alpha)
Image
modifyAlphaWithTranslucency
in class Image
alpha
- New value for the entire alpha channelpublic Image modifyAlpha(byte alpha, int removeColor)
Image
modifyAlpha
in class Image
alpha
- New value for the entire alpha channelremoveColor
- pixels matching this color are made transparent (alpha channel ignored)public Graphics getGraphics()
Image
getGraphics
in class Image
protected void tileRect(Graphics g, Object nativeGraphics, int x, int y, int rect_width, int rect_height)
Image
public Image scaled(int width, int height, boolean shared)
Image
Image.scale(int, int)
. The additional boolean
parameter indicates if the returned scaled image should share the
underlying native image. In case shared is false, this method will
create a scaled copy of the underlying native image. In case shared is
true, a scaled copy of the underlying native image will only be created
when either the scaled or the unscaled peer get mutated (copy-on-write
idiom). In particular, no copy will ever get created in the common case
where the unscaled and scaled image never mutate.
scaled(w,h) is equivalent to scaled (w,h,true).
The method accepts -1 to preserve aspect ratio in the given axis.width
- width for the scalingheight
- height of the scaled imageshared
- true whenever the scaled and unscaled image shall share the same native imagepublic Object getImage()
Image
public void scale(int width, int height)
Image
public boolean isAnimation()
Image
isAnimation
in class Image