Hi Ken,
QUESTION: does anyone have an idea of how to handle this situation?
Shouldn't ImageFetcher.run() throw something? Like an OutOfMemoryError
or something so that grabPixels() can throw an InterruptedException like
the documentation says it will???
The ImageFetcher should capture any errors and pass on an ERROR
condition to all ImageConsumers. Is that happening here?
My suggestion would be to use ImageIO instead of the Toolkit image
facility for a couple of reasons:
- Getting pixels via PixelGrabber goes through some really indirect
mechanisms that should be slower than ImageIO (YMMV as we haven't
necessarily benchmarked your particular usage, but it would be a safe bet).
- ImageIO does the image loading in your own thread so you can catch
such errors and deal with them with a lot less fuss.
- ImageIO will deliver you one single copy of the image - when you use
PixelGrabber and Toolkit images then you run the risk of the Toolkit
image storing the pixels itself and then also feeding them to your
PixelGrabber which would double the amount of memory needed and the
memory used for the Toolkit image is harder to control since it is
managed by another mechanism (hint: Image.flush() should get rid of it,
but be careful not to trigger it to reload the image data again in the
future). To give you an idea - image.getWidth(canvas) is enough to
trigger the Toolkit image to load and store its own version of the image.
- Also, if the Toolkit image is loading its own version of the image in
addition to the data it delivers to your PixelGrabber, that is even more
of a performance loss.
- (BTW, PixelGrabber can get the W/H itself and create an array for you
if you use the PixelGrabber(image, 0, 0, -1, -1, forceRGB) constructor.
That would avoid the "second copy loaded for the Toolkit image"
problem...)
Have you tried ImageIO?
...jim
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".