|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--waba.fx.Image
Image is a rectangular image.
You can draw into an image and copy an image to a surface using a Graphics object. Before a image is drawn, its palette is set.
Graphics| Field Summary | |
protected int |
height
|
int[] |
palRGBs
Contains the palette RGBs. |
int[][] |
pixels
On desktop, contains the pixels of this image. |
protected Palette |
savingPal
Used on desktop only to match the colors that are being saved with the colors that are being getted when saving a bitmap |
Color |
transparentColor
Deprecated. use transparentPixel instead, or get/setTransparentColor |
int |
transparentPixel
Sets the transparent pixel of this image. |
protected int |
width
|
| Constructor Summary | |
protected |
Image()
Used by classes that extends the Image class |
|
Image(byte[] fullBmpDescription)
Parses an image from the given byte array. |
|
Image(int width,
int height)
Creates an image of the specified width and height. |
|
Image(java.lang.String path)
Loads and constructs an image from a file. |
| Method Summary | |
void |
applyPalette()
apply the palette used by this bitmap to the display |
void |
changeColors(Color from,
Color to)
Changes all the pixels of the image from one color to the other. |
int |
createBmp(DataStream ds)
saves this image as a Windows .bmp file format, with the same bpp of the screen using the current palette of this image, to the given DataStream. |
void |
free()
Sets the image width and height to 0 and frees any systems resources associated with the image. |
Graphics |
getGraphics()
Returns a new Graphics instance that can be used to drawing in this image. |
int |
getHeight()
Returns the height of the image. |
Palette |
getPalette()
returns the palette associated with this image. |
protected void |
getPixelRow(byte[] fillIn,
int y)
used in saveTo method. fill in the y row into the fillIn array. there must be enough space for the full line be filled. |
Image |
getRotatedScaledInstance(int scale,
int angle,
Color fill)
Creates a rotated and/or scaled version of this Image. |
Image |
getScaledInstance(int newWidth,
int newHeight)
Returns the scaled instance for this picture. |
Image |
getTouchedUpInstance(byte brightness,
byte contrast)
Creates a touched-up version of this Image with the specified brightness and contrast. |
Color |
getTransparentColor()
Gets the transparent color of this image. |
int |
getWidth()
Returns the width of the image. |
void |
load(Stream inputStream)
Not implemented by this class. |
int |
saveTo(Catalog cat,
java.lang.String name)
saves this image as a Windows .bmp file format to the given Catalog. |
Image |
scaledBy(float scaleX,
float scaleY)
Returns the scaled instance for this picture, given the scale arguments. |
void |
setPalette(Palette pal)
substitutes the original palette that came with this image with the given one. |
void |
setTransparentColor(Color c)
Sets the transparent color of this image. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected int width
protected int height
public int transparentPixel
public int[] palRGBs
protected Palette savingPal
public int[][] pixels
public Color transparentColor
| Constructor Detail |
protected Image()
public Image(int width,
int height)
Image img = new Image(100,100); Graphics g = img.getGraphics(); g.setBackColor(Color.WHITE); g.fillRect(25,25,50,50); ... Graphics screenG = createGraphics(); screenG.drawImage(img,CENTER,CENTER);
public Image(java.lang.String path)
Important optimization trick: if your image has large parts of white pixels, it will load faster (in other words, use white as background when possible).
For color devices, it is strongly recommended that your images have all the same palette (the web-safe, from SuperWabaSDK/samples/WebSafePalette), non-compressed bmps, because the load time is cut by 100 times!
public Image(byte[] fullBmpDescription)
// create the image and fill it with something
Image img = new Image(160,160);
Graphics g = img.getGraphics();
for (int i =0; i < 16; i++)
{
g.setBackColor(new Color(10*i,10*i,10*i));
g.fillRect(i*10,0,10,160);
}
// save the bmp in a byte stream
ByteArrayStream bas = new ByteArrayStream(4096);
DataStream ds = new DataStream(bas);
int totalBytesWritten = img.createBmp(ds);
// parse the saved bmp
Image im = new Image(bas.getBuffer()); // Caution! the buffer may be greater than totalBytesWritten, but when parsing theres no problem.
if (im.getWidth() > 0) // successfully parsed?
{
createGraphics().drawImage(im,CENTER,CENTER);
Vm.sleep(2000);
}
| Method Detail |
public void load(Stream inputStream)
public void free()
public int getHeight()
public int getWidth()
public Graphics getGraphics()
public void setTransparentColor(Color c)
myImage.applyPalette before calling
setTransparentColor (or before the first time the image is drawn),
otherwise the color may not be found in the active palette.public Color getTransparentColor()
public void changeColors(Color from,
Color to)
public Palette getPalette()
public void setPalette(Palette pal)
public int saveTo(Catalog cat,
java.lang.String name)
Here is an usage example:
// create the image and paint over it
Image img = new Image(100,100);
Graphics g = img.getGraphics();
g.setBackColor(Color.getColor(100,150,200));
g.fillRect(25,25,50,50);
g.setForeColor(Color.WHITE);
g.drawCircle(50,50,20);
// create the catalog to save the image. You must change CRTR to match your apps creator ID
Catalog cat = new Catalog("images.CRTR.SWAX", Catalog.CREATE);
img.saveTo(cat, "boxcircle.bmp");
cat.close();
// load the previously created image
if (Vm.attachLibrary("images.CRTR")) // must add the creator so it can be used in desktop. The type is always SWAX
{
Image im = new Image("boxcircle.bmp");
if (im.getWidth() > 0) // successfully loaded?
createGraphics().drawImage(im,CENTER,CENTER);
}
createBmp(waba.io.DataStream)public int createBmp(DataStream ds)
saveTo(waba.io.Catalog, java.lang.String)
protected void getPixelRow(byte[] fillIn,
int y)
public void applyPalette()
public Image getScaledInstance(int newWidth,
int newHeight)
if (Settings.isColor)
{
Palette pal = scaledImg.getPalette();
createGraphics().applyPalette(pal,0,pal.size()-1); // apply the colors of the new image.
}
public Image scaledBy(float scaleX,
float scaleY)
if (Settings.isColor)
{
Palette pal = scaledImg.getPalette();
createGraphics().applyPalette(pal,0,pal.size()-1); // apply the colors of the new image.
}
public Image getRotatedScaledInstance(int scale,
int angle,
Color fill)
IMPORTANT: This method does not work on Palm OS; the same image is returned.
A newImage object is returned which will render
the image at the specified scale ratio and
rotation angle.
After rotation, the empty parts of the rectangular area of
the resulting image are filled with the fill color.
If color is null, then
the fill color is the transparent color, or white if none.
Notes
- the new image will probably have a different size of this image.
- if you want just to scale, use the getScaledInstance or
scaleBy instead, because they are faster.
scale - a number greater than or equal to 0 stating the percentage
of scaling to be performed.
100 is not scaling, 200 doubles the size, 50 shrinks the image by 2angle - the rotation angle, expressed in trigonometric degreesfill - the fill color.
null indicates the transparent color of this image or
Color.WHITE if the transparentPixel was not set.
public Image getTouchedUpInstance(byte brightness,
byte contrast)
IMPORTANT: This method does not work on Palm OS; the same image is returned.
A newImage object is returned which will render
the image at the specified brigthnessand
the specified contrast.brightness - a number between -128 and 127 stating the desired
level of brightness.
127 is the highest brightness level (white image),
-128 is no brightness (darkest image).contrast - a number between -128 and 127 stating the desired
level of contrast.
127 is the highest contrast level,
-128 is no contrast.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||