public class Mask extends Object
Each scan line of the mask is byte aligned and the number of bytes needed to cover an Image will be height*((width+7)/8)
Modifier and Type | Field and Description |
---|---|
protected byte[] |
bits
This is the inclusion bitmap for the mask.
|
protected int |
height
The height of the mask.
|
protected int |
width
The width of the mask.
|
Constructor and Description |
---|
Mask()
Create an empty Mask.
|
Mask(ImageData imageMask)
Create a new Mask from an Image.
|
Mask(ImageData image,
Color transparent)
Create a new Mask from an Image and a transparent color.
|
Mask(int width,
int height)
Create a Mask with the specified width and height.
|
Mask(int width,
int height,
byte[] bits)
Create a Mask with the specified width and height and using the specified bits.
|
Mask(String maskImageName) |
Modifier and Type | Method and Description |
---|---|
static void |
blend(Image dest,
Image src,
int destX,
int destY,
int width,
int height,
int srcX,
int srcY) |
static void |
blend(int[] dest,
int[] src) |
void |
clear()
Fill the bits with zeros, but only up to the number of bytes needed for the Mask.
|
boolean |
fromImage(ImageData image)
Get the bits for this mask from the alpha channel or transparent color in the image.
|
boolean |
fromImageColor(ImageData image,
Color transparentColor)
Get the bits for this mask from the transparent color in the image.
|
void |
fromImageMask(ImageData imageMask)
Set this Masks bits based on the provided monochrome (B/W) imageMask image.
|
byte[] |
getBitmap()
Returns the actual bit map used by the mask.
|
Mask |
getCopy()
Return a copy of this mask, with its own new bit map.
|
int |
getHeight() |
int |
getWidth() |
static boolean |
hasTrueAlpha(Image im) |
void |
intersection(Mask other)
This leaves included only bits which are included in both this Mask and the other Mask.
|
void |
invert()
This inverts the bitmap for the mask.
|
void |
invert(Mask other)
This inverts all the bits in this Mask which correspond to set bits in the other Mask.
|
static Picture |
maskImage(ImageData original,
Object maskObject) |
void |
sizeTo(int width,
int height)
This resizes the Mask, invalidating the data within it.
|
void |
sizeTo(int width,
int height,
boolean reduceBits)
This resizes the Mask, invalidating the data within it.
|
Image |
toImageMask()
This converts this bitmap to an Image based Mask for use with Drawings and Graphics.drawImage() methods.
|
void |
union(Mask other)
This unions two masks together.
|
protected int width
protected int height
protected byte[] bits
public Mask(int width, int height, byte[] bits)
width
- The width of the mask.height
- The height of the mask.bits
- The bits for the mask.
This must be the correct size (or greater) otherwise an exception will be thrown.public Mask(int width, int height)
width
- The width of the mask.height
- The height of the mask.public Mask(ImageData imageMask)
imageMask
- The Image mask where White pixel represent excluded bits and Black pixels
represent included bits.public Mask(ImageData image, Color transparent)
image
- The image.transparent
- A transparent color. All bits in the image that are of this color are
considered excluded from the mask, and all other bits are considered included.public Mask(String maskImageName) throws ImageDecodingException
ImageDecodingException
public Mask()
public Mask getCopy()
public int getWidth()
public int getHeight()
public void sizeTo(int width, int height, boolean reduceBits)
width
- The new width.height
- The new height.reduceBits
- if this is true and the number of bytes needed is less
than the number of bits it has, then it will create and use a smaller byte array.public void sizeTo(int width, int height)
width
- The new width.height
- The new height.reduceBits
- if this is true and the number of bytes needed is less
than the number of bits it has, then it will create and use a smaller byte array.public void clear()
public byte[] getBitmap()
public void invert()
public void union(Mask other)
other
- The other Mask, which must be the same dimensions as this Mask.public void intersection(Mask other)
other
- The other Mask, which must be the same dimensions as this Mask.public void invert(Mask other)
other
- The other Mask, which must be the same dimensions as this Mask.public Image toImageMask()
public void fromImageMask(ImageData imageMask)
public boolean fromImageColor(ImageData image, Color transparentColor)
image
- The image to create a mask for.public boolean fromImage(ImageData image)
image
- The image to create a mask for.public static boolean hasTrueAlpha(Image im)
public static void blend(Image dest, Image src, int destX, int destY, int width, int height, int srcX, int srcY) throws IllegalArgumentException
IllegalArgumentException
public static void blend(int[] dest, int[] src) throws IllegalArgumentException
IllegalArgumentException