Troubleshooting guide

49
2: Using graphics and multimedia
Determine the raster
operations that the
application supports.
1. Invoke Graphics.isRopSupported(int).
2. Provide one of the following constants as a parameter:
ROP_CONST_GLOBALALPHA: blends the constant foreground color using a constant global alpha
value with destination pixels
ROP_SRC_GLOBALALPHA: blends a source bitmap using a constant global alpha value with
destination pixels
Draw a set of shaded, filled
paths.
> Invoke Graphics.drawShadedFilledPath():
public void drawShadedFilledPath(int[] xPts, int[] yPts, byte[] pointTypes,
int[] colors, int[] offsets);
The following example draws a path that blends from blue to red:
Bitmap surface = new Bitmap(240, 160);
BitmapField surfaceField = new BitmapField(surface);
add(surfaceField);
Graphics graphics = new Graphics(surface);
int[] X_PTS = { 0, 0, 240, 240 };
int[] Y_PTS = { 20, 50, 50, 20 };
int[] drawColors = { 0x0000CC, 0x0000CC, 0xCC0000, 0xCC0000 };
try {
graphics.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);
} catch (IllegalArgumentException iae) {
System.out.println("Bad arguments.");
}
Turn a drawing style on. >Invoke Graphics.setDrawingStyle(int drawStyle, boolean on).
Turn a drawing style off. >Invoke Graphics.setDrawingStyle(int drawStyle, boolean off).
Determine if a drawing style
is set.
>Invoke Graphics.isDrawingStyleSet(int drawStyle).
Use a monochrome bitmap as
a stamp.
> To let applications use monochrome bitmaps as stamps by rendering the nontransparent region in color,
use the
STAMP_MONOCHROME option. This option applies to bitmaps that are 1 bit and have alpha defined.
BitmapField field = new BitmapField(original, BitmapField.STAMP_MONOCHROME);
Draw an image on an empty
bitmap.
1. Create an empty bitmap. The example that follows copies the type and size from an existing bitmap.
Bitmap restored = new Bitmap(original.getType(),
original.getWidth(), original.getHeight());
2. Create a Graphics object using the empty bitmap as the drawing surface.
Graphics graphics = new Graphics(restored);
3. To draw a new image using raw data retrieved from the original, invoke Graphics.drawRGB().
try {
graphics.drawRGB(argb, 0, restored.getWidth(), 0, 0, restored.getWidth(),
restored.getHeight());
} catch(Exception e) {
System.out.println("Error occurred during drawing: " + e);
}
Task Steps