|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.fx.PixelBuffer
A PixelBuffer is used to store ARGB pixel information in an integer array. This is unlike an Image, which uses a system dependant image implementation. However there are some methods, such as draw() which will cause the pixel buffer to create an Image from its data for rendering.
PixelBuffers are generally used for composing complex images with alpha (transparency) channels. This may be necessary because the normal draw operations done via a Graphics object do not support the writing of alpha channel data. For example, you cannot use fillRect() to fill an area of a drawing surface with a particular color that has an alpha channel. However using PixelBuffer.addAlphaChannel(Image im,Color transparent) will allow you to add an alpha channel to a previous drawn image.
Any Images created out of the data from the PixelBuffer will be considered to have an alpha (transparency) channel.
| Field Summary | |
Color |
background
The background for use when drawing via draw(). |
static int |
PUT_BLEND
This is used with put() - it alpha blends in the incoming data with this PixelBuffer's data. |
static int |
PUT_NONTRANSPARENT_ONLY
This is used with put() and the PUT_SET option - it overwrites this PixelBuffer's data with in the incoming data so long as the incoming data is NOT FULLY TRANSPARENT (i.e an alpha value of 0). |
static int |
PUT_SET
This is used with put() - it overwrites this PixelBuffer's data with in the incoming data. |
static int |
SCALE_KEEP_ASPECT_RATIO
An option for scale(). |
static int |
TRANSFORM_MIRROR_HORIZONTAL
This is a transformation for the transform() method. |
static int |
TRANSFORM_MIRROR_VERTICAL
This is a transformation for the transform() method. |
static int |
TRANSFORM_ROTATE_180
This is a transformation for the transform() method. |
static int |
TRANSFORM_ROTATE_270
This is a transformation for the transform() method. |
static int |
TRANSFORM_ROTATE_90
This is a transformation for the transform() method. |
| Fields inherited from interface ewe.fx.IImage |
DISABLED, OUTLINED |
| Constructor Summary | |
PixelBuffer(IImage from)
|
|
PixelBuffer(IImage from,
Rect area)
|
|
PixelBuffer(IImage from,
Rect sourceArea,
Dimension newSize,
Object useBuffer)
|
|
PixelBuffer(int width,
int height)
|
|
PixelBuffer(int width,
int height,
int[] bufferToUse)
|
|
| Method Summary | |
void |
blend(PixelBuffer other,
int x,
int y)
This is the same as put(other,x,y,PUT_BLEND). |
void |
bufferChanged()
If you modify the pixels in the buffer as provided by getBuffer(), then call this method to let the buffer know about the changes. |
void |
draw(Graphics g,
int x,
int y,
int options)
Draw the full image at the specified co-ordinates in the graphics provided. |
void |
free()
This frees system resources associated with the Image. |
PixelBuffer |
getArea(int x,
int y,
int width,
int height)
|
Color |
getBackground()
This returns a background color if one is set for the image. |
int[] |
getBuffer()
This exposes the internal buffer that contains the pixel data. |
Graphics |
getDrawingBuffer(Rect area,
Color transparent,
double alphaValue)
This will create a drawing surface, initially filled with the supplied transparent color. |
int |
getHeight()
This returns the height of the image. |
static PixelBuffer |
getImageSection(IImage image,
Mask m,
Point p,
double alphaValue)
This gets a section of an Image, starting at a particular point and in a shape represented by Mask. |
int[] |
getPixels(int[] dest,
int offset,
int x,
int y,
int w,
int h,
int options)
Retrieve the pixels from the Image in encoded ARGB values. |
static int[] |
getPixelsFor(IImage image,
int[] dest,
int offset,
Rect area,
int options,
Color substituteBackground)
This will attempt to get pixels for an IImage. |
int |
getWidth()
This returns the width of the image. |
void |
put(PixelBuffer other,
int x,
int y,
int operation)
This merges the pixels from the other PixelBuffer with the pixels in this PixelBuffer at the specified location. |
void |
put(PixelBuffer other,
int x,
int y,
int operation,
Mask mask)
This merges the pixels from the other PixelBuffer with the pixels in this PixelBuffer at the specified location. |
void |
putDrawingBuffer(int operation)
Call this after calling getDrawingBuffer() to update this PixelBuffer with the data you have drawn. |
void |
putDrawingBuffer(int operation,
Mask mask)
Call this after calling getDrawingBuffer() to update this PixelBuffer with the data you have drawn, in the area specified by the mask. |
PixelBuffer |
scale(int newWidth,
int newHeight)
|
PixelBuffer |
scale(int newWidth,
int newHeight,
Object useBuffer)
|
PixelBuffer |
scale(int newWidth,
int newHeight,
Rect sourceArea,
int scaleOptions,
Object useBuffer)
Scale the PixelBuffer to produce a new PixelBuffer - optionally scaling only a portion of the original PixelBuffer. |
void |
scaleAlpha(double byHowMuch)
This method will go through the pixel buffer data and scale the alpha value of each pixel by the specified amount - not allowing any alpha value to go higher than 1.0. |
void |
setAlpha(Color transparent,
double alpha)
This method will go through the pixel buffer data and set the alpha value of each pixel to the specified value (between 0.0 and 1.0), EXCEPT for any pixels that is equal to the transparent Color - those pixels will be set to have an alpha value of 0. |
void |
setAlpha(double alpha)
This method will go through the pixel buffer data and set the alpha value of each pixel to the specified value (between 0.0 and 1.0). |
void |
setAlpha(Mask mask,
double alpha)
This method will go through the pixel buffer data and set the alpha value of each pixel which is included in the mask. |
Image |
toDrawableImage()
This returns a new Image (which can be drawn on) from the pixels within this PixelBuffer. |
static Object |
toIcon(IImage image)
This creates a native Icon to be used in (say) a TaskbarWindow or Window, given any IImage object. |
Image |
toImage()
This returns a new ready for display Image with an alpha channel from the pixels within this PixelBuffer. |
Mask |
toMask()
Convert the PixelBuffer to a Mask where all black pixels are opaque and white pixels are transparent. |
mImage |
toMImage()
This returns a new ready for display mImage with an alpha channel from the pixels within this PixelBuffer. |
PixelBuffer |
transform(int transformation,
Object useBuffer)
This does one of a number of specific transformations on the PixelBuffer. |
boolean |
usesAlpha()
This always returns true. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public Color background
public static final int PUT_BLEND
public static final int PUT_SET
public static final int PUT_NONTRANSPARENT_ONLY
public static final int SCALE_KEEP_ASPECT_RATIO
public static final int TRANSFORM_ROTATE_90
public static final int TRANSFORM_ROTATE_180
public static final int TRANSFORM_ROTATE_270
public static final int TRANSFORM_MIRROR_HORIZONTAL
public static final int TRANSFORM_MIRROR_VERTICAL
| Constructor Detail |
public PixelBuffer(int width,
int height,
int[] bufferToUse)
throws IllegalArgumentException
public PixelBuffer(int width,
int height)
throws IllegalArgumentException
public PixelBuffer(IImage from,
Rect area)
throws IllegalArgumentException
public PixelBuffer(IImage from)
throws IllegalArgumentException
public PixelBuffer(IImage from,
Rect sourceArea,
Dimension newSize,
Object useBuffer)
| Method Detail |
public int[] getBuffer()
public void bufferChanged()
public int getWidth()
IImage
getWidth in interface IImagepublic int getHeight()
IImage
getHeight in interface IImagepublic void free()
IImage
free in interface IImage
public void blend(PixelBuffer other,
int x,
int y)
public void put(PixelBuffer other,
int x,
int y,
int operation)
other - The other PixelBuffer to merge with this one.x - The x location where the incoming PixelBuffer should be put.y - The y location where the incoming PixelBuffer should be put.operation - This should be either PUT_SET or PUT_BLEND. If PUT_SET is used you can
also specify PUT_NONTRANSPARENT_ONLY which tells it to replace pixels in this PixelBuffer
ONLY if the corresponding incoming pixels are not fully transparent.
public void put(PixelBuffer other,
int x,
int y,
int operation,
Mask mask)
other - The other PixelBuffer to merge with this one.x - The x location where the incoming PixelBuffer should be put.y - The y location where the incoming PixelBuffer should be put.operation - This should be either PUT_SET or PUT_BLEND.mask - A mask specifying which incoming pixels should be merged with the Pixels in
this PixelBuffer.public void setAlpha(double alpha)
alpha - The alpha value between 0.0 and 1.0
public void setAlpha(Color transparent,
double alpha)
transparent - the transparent Color.alpha - The alpha value between 0.0 and 1.0
public void setAlpha(Mask mask,
double alpha)
mask - The pixel mask.alpha - The alpha value between 0.0 and 1.0public void scaleAlpha(double byHowMuch)
public Color getBackground()
IImage
getBackground in interface IImagepublic boolean usesAlpha()
usesAlpha in interface IImage
public Graphics getDrawingBuffer(Rect area,
Color transparent,
double alphaValue)
area - An area within the pixbuf to use - will default to the entire area if null.transparent - The initial color to consider the transparent color when putting
the area back into the PixelBuffer, or Color(80,255,80) if none is supplied.alphaValue - the alphaValue to set all the non-transparent pixels to (between 0.0 and 1.0).
public void putDrawingBuffer(int operation)
operation - One of PUT_BLEND or PUT_SET
public void putDrawingBuffer(int operation,
Mask mask)
operation - One of PUT_BLEND or PUT_SETmask - A mask specifying which pixels should be put. Any pixels not in this area are unchanged.public Image toImage()
public Image toDrawableImage()
public mImage toMImage()
public void draw(Graphics g,
int x,
int y,
int options)
IImage
draw in interface IImage
public PixelBuffer getArea(int x,
int y,
int width,
int height)
throws IllegalArgumentException
IllegalArgumentException
public PixelBuffer scale(int newWidth,
int newHeight,
Object useBuffer)
public PixelBuffer scale(int newWidth,
int newHeight)
public Mask toMask()
public PixelBuffer scale(int newWidth,
int newHeight,
Rect sourceArea,
int scaleOptions,
Object useBuffer)
throws IllegalArgumentException
newWidth - The width of the new PixelBuffer.newHeight - The height of the new PixelBuffer.sourceArea - An optional rectangle specifying the source area in this PixelBuffer.
If it is null then entire area is used.scaleOptions - This can be zero or SCALE_KEEP_ASPECT_RATIO.useBuffer - An optional re-usable buffer to use for the data calculations. It can
be a ByteArray or a byte [] object or it can be a PixelBuffer. If useBuffer is a PixelBuffer
its data buffer will be used (if big enough) and its width and height will be adjusted
and that PixelBuffer will be returned.
IllegalArgumentException - If there was an error with any of the arguments.
public PixelBuffer transform(int transformation,
Object useBuffer)
transformation - One of the TRANSFORM_XXX values.useBuffer - An optional byte [] or ByteArray object to use as the buffer for the
newly created PixelBuffer
public int[] getPixels(int[] dest,
int offset,
int x,
int y,
int w,
int h,
int options)
throws IllegalArgumentException
IImage
getPixels in interface IImagedest - The destination int array. If this is null then a new array should be created.offset - The offset into the array to start placing pixels.x - the x co-ordinate within the image.y - the y co-ordinate within the image.w - the width of the pixel block to get.h - the height of the pixel block to get.options - options for retrieving pixels - currently unused.
IllegalArgumentException
public static int[] getPixelsFor(IImage image,
int[] dest,
int offset,
Rect area,
int options,
Color substituteBackground)
public static PixelBuffer getImageSection(IImage image,
Mask m,
Point p,
double alphaValue)
image - The original image.m - The mask representing the bits of the Image that should be taken. This Mask can be
smaller than the full image - the p parameter specifies where in the image the section should
be taken from.p - The point in the Image where the section should be taken from.alphaValue - An alpha value to be applied to all pixels taken from the Image.
public static Object toIcon(IImage image)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||