The code on the right demonstrates the use of a
Raster object. The running Applet is shown below. Clicking on the
image will cause it to be negated.
The source code for this applet can be downloaded here: Rastest.java.
|
import java.applet.*;
import java.awt.*;
import Raster;
public class Rastest extends Applet {
Raster raster;
Image output;
int count = 0;
public void init() {
String filename = getParameter("image");
output = getImage(getDocumentBase(), filename);
raster = new Raster(output);
showStatus("Image size: " + raster.getWidth() + " x " + raster.getHeight());
}
public void paint(Graphics g) {
g.drawImage(output, 0, 0, this);
count += 1;
showStatus("paint() called " + count + " time" + ((count > 1) ? "s":""));
}
public void update(Graphics g) {
paint(g);
}
public boolean mouseUp(Event e, int x, int y) {
int s = raster.getSize();
int [] pixel = raster.getPixelBuffer();
for (int i = 0; i < s; i++) {
raster.pixel[i] ^= 0x00ffffff;
}
output = raster.toImage(this);
repaint();
return true;
}
}
|