I wrote an application that displays continuously images
retreived by a framegrabber. Currently I use the MemoryImageSource
class. The grayscale image data is stored in a byte array which is
steadily updated by a native dll.
Here is the code of the displaying canvas:
private class RealDisplay extends Canvas
{
private Image image;
public RealDisplay()
{
ComponentColorModel colorModel =
new CommponentColorModel(
ColorSpace.getInstance( ColorSpace.CS_GRAY ),
new int[] { 8 }, false, false,
ColorModel.OPAQUE, DataBuffer.TYPE_BYTE );
producer = new MemoryImageSource( imgWidth, imgHeight,
colorModel, FrameGrabber.getImageData(), 0, imgWidth );
producer.setAnimated( true );
image = createImage( producer );
}
public void update( Graphics g )
{
g.drawImage( image, 0, 0, Display.this );
}
public void paint( Graphics g )
{
g.drawImage( image, 0, 0, Display.this );
}
}
Here is the run method of the updating thread:
public void run()
{
while( update )
{
FrameGrabber.grab();
producer.newPixels();
canvas.repaint();
}
}
The FrameGrabber.grab() method updates the byte array which was before
passed to
the MemoryImageSource constructor.
My Questions are:
Why do I have to call the newPixels() method of the producer although I
did not assign any ImageConsumer to it? ( This method seems to demand
a lot of CPU power )
What other classes could I use to achieve a better performance?