import java.awt.image.*; import java.awt.*; import java.net.*; // This class fetches an image from an URL, and processes it class ImageFetcher implements ImageObserver { Preferences prefs; ImageFetcher(Preferences pprefs) { prefs = pprefs; // This creates a new URL URL url = null; try { url = new URL(prefs.urlString); } catch (Exception e) { Image2HTML.ErrorExit("Unable to parse url " + url); } Image image = null; try { image = Toolkit.getDefaultToolkit().getImage(url); } catch (Exception e) { Image2HTML.ErrorExit("Unable to parse url " + url); } Toolkit.getDefaultToolkit().prepareImage(image, -1, -1, this); } // ImageFetcher constructor // This is called when the image is updated public boolean imageUpdate(Image image, int infoflags, int x, int y, int width, int height) { // If an error occurred, report it if ((infoflags & ERROR) != 0) Image2HTML.ErrorExit("Unable to read image from " + prefs.urlString + "; please verify that this is really the URL of an image (GIF or JPEG) file."); // If we're done reading this image, process it if ((infoflags & ALLBITS) != 0) { // If this is CGI mode, report the image size if (prefs.cgi) { System.out.println("IMAGE_HEIGHT: " + height); System.out.println("IMAGE_WIDTH: " + width); } // Process the image (generate the HTML table) ImageProcessor imageProcessor = new ImageProcessor(image, width, height, prefs); imageProcessor.start(); } // if done reading image return true; } //==== imageUpdate() ====// } // class ImageFetcher