/** * Creates a new JpegEncoder object. * * @param image DOCUMENT ME! * @param quality DOCUMENT ME! * @param tOut DOCUMENT ME! */ public JpegEncoder(Image image, int quality, OutputStream tOut) { MediaTracker tracker = new MediaTracker(this); tracker.addImage(image, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { // Got to do something? } /* * Quality of the image. * 0 to 100 and from bad image quality, high compression to good * image quality low compression */ Quality = quality; /* * Getting picture information * It takes the Width, Height and RGB scans of the image. */ JpegObj = new JpegInfo(image); imageHeight = JpegObj.imageHeight; imageWidth = JpegObj.imageWidth; // CoHort: out could be an internal OutputStream, but pointless, // since I pass it a OutputStream already. out = tOut; dct = new DCT(Quality); Huf = new Huffman(imageWidth, imageHeight); }
/** * Load images (used for preloading images). * * @param images Array of <code>Image</code> instances to preload. * @param comp Component that will observe the loading state of the images. */ public static void loadImages(Image[] images, Component comp) { MediaTracker tracker = new MediaTracker(comp); for (int i = 0; i < images.length; i++) tracker.addImage(images[i], 0); try { tracker.waitForID(0); } catch (InterruptedException ignore) { } }
public static void ensureLoaded(Image img) throws Exception { // System.err.println("In ensureloaded"); mediatracker.addImage(img, 0); try { mediatracker.waitForAll(); if (mediatracker.getErrorsAny() != null) { mediatracker.removeImage(img); throw new Exception("Error loading image"); } } catch (InterruptedException e) { e.printStackTrace(); } mediatracker.removeImage(img); // System.err.println("Out ensureloaded"); }
/** Make (scale down) the thumbnail */ private Image getScaledImage(Image image, int breite, int hoehe) { Image scaledImage = image.getScaledInstance(breite, hoehe, Image.SCALE_DEFAULT); try { MediaTracker mediaTracker = new MediaTracker(new Container()); mediaTracker.addImage(scaledImage, 0); mediaTracker.waitForID(0); } catch (InterruptedException e) { return null; } return scaledImage; }
// load the images when the applet begins executing public void init() { int i; this.processHTMLParameters(); if (totalImages == 0 || imageName == null) { this.showStatus("Invalid parameters"); this.destroy(); } images = new Vector(totalImages, 1); imageTracker = new MediaTracker(this); for (i = 0; i < totalImages; i++) { images.addElement(this.getImage(this.getDocumentBase(), "images/" + imageName + i + ".gif")); // track loading image imageTracker.addImage((Image) images.elementAt(i), i); } // wait for the first image, // must use a Joos version of tracker to avoid catching // interruped exception new JoosMediaTracker(imageTracker).waitForID(0); width = ((Image) images.elementAt(0)).getWidth(this); height = ((Image) images.elementAt(0)).getHeight(this); this.resize(width, height + 30); buffer = this.createImage(width, height); gContext = buffer.getGraphics(); // set background of buffer to white gContext.setColor(c.white()); gContext.fillRect(0, 0, 160, 80); this.setLayout(new BorderLayout(10, 10)); sleepLabel = new Label("Sleep time", c.LABEL_CENTER()); sleepDisplay = new TextField("", 5); sleepDisplay.setText(new Integer(sleepTime).toString()); sleepStuff = new Panel(); sleepStuff.add(sleepLabel); sleepStuff.add(sleepDisplay); new JoosContainer(this).addString("South", sleepStuff); }
/** Read the thumbnail */ private Image readImageThumbnail(File fileThumbnail) { Image image = null; try { image = Toolkit.getDefaultToolkit().getImage(fileThumbnail.getPath()); MediaTracker mediaTracker = new MediaTracker(new Container()); mediaTracker.addImage(image, 0); mediaTracker.waitForID(0); } catch (InterruptedException e) { // System.out.println("ERROR: InterruptedException beim Lesen thumbnail (" + // fileThumbnail.getPath() // + "). " + e); return null; } return image; }
private static BufferedImage convertToBufferedImage(Image image) throws IOException { if (image instanceof BufferedImage) { return (BufferedImage) image; } else { MediaTracker tracker = new MediaTracker(null /*not sure how this is used*/); tracker.addImage(image, 0); try { tracker.waitForAll(); } catch (InterruptedException e) { throw new IOException(e.getMessage()); } BufferedImage bufImage = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics g = bufImage.createGraphics(); g.drawImage(image, 0, 0, null); return bufImage; } }
public static java.awt.image.BufferedImage loadBufferedImageFromResources( Component c, String filename) { try { Misc m = new Misc(); java.awt.Image img = loadImageFromResources(filename); MediaTracker mt = new MediaTracker(c); mt.addImage(img, 0); mt.waitForID(0); int width = img.getWidth(null); int height = img.getHeight(null); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics gg = bi.getGraphics(); gg.drawImage(img, 0, 0, null); gg.dispose(); return bi; } catch (Exception ex) { System.out.println(ex.toString()); } return null; }
/** * Konstruktor MapView Aufgabe ist das Setzen der WorldMap und die Hintergrundgrafik (Landkarte) * zu setzen. * * @param worldMap Zum View gehoerige Instanz der Klasse WorldMap. */ public MapView(WorldMap worldMap) { this.worldMap = worldMap; this.territoryBattle = new ArrayList<Territory>(); this.setLayout(null); String path = System.getProperty("java.class.path") + "/risk/maps/" + worldMap.getGraphic(); // String path = "/home/swa/Desktop/maps/"+worldMap.getGraphic(); MediaTracker mt = new MediaTracker(this); this.img = Toolkit.getDefaultToolkit().getImage(path); mt.addImage(this.img, 0); try { mt.waitForAll(); } catch (InterruptedException e) { e.printStackTrace(); } this.setPreferredSize(new Dimension(img.getWidth(null), img.getHeight(null))); this.setVisible(true); }
// // Build installer window // public static void showInstallerWindow() { _installerFrame = new JFrame(Config.getWindowTitle()); Container cont = _installerFrame.getContentPane(); cont.setLayout(new BorderLayout()); // North pane Box topPane = new Box(BoxLayout.X_AXIS); JLabel title = new JLabel(Config.getWindowHeading()); Font titleFont = new Font("SansSerif", Font.BOLD, 22); title.setFont(titleFont); title.setForeground(Color.black); // Create Sun logo URL urlLogo = Main.class.getResource(Config.getWindowLogo()); Image img = Toolkit.getDefaultToolkit().getImage(urlLogo); MediaTracker md = new MediaTracker(_installerFrame); md.addImage(img, 0); try { md.waitForAll(); } catch (Exception ioe) { Config.trace(ioe.toString()); } if (md.isErrorID(0)) Config.trace("Error loading image"); Icon sunLogo = new ImageIcon(img); JLabel logoLabel = new JLabel(sunLogo); logoLabel.setOpaque(true); topPane.add(topPane.createHorizontalStrut(5)); topPane.add(title); topPane.add(topPane.createHorizontalGlue()); topPane.add(logoLabel); topPane.add(topPane.createHorizontalStrut(5)); // West Pane Box westPane = new Box(BoxLayout.X_AXIS); westPane.add(westPane.createHorizontalStrut(10)); // South Pane Box bottomPane = new Box(BoxLayout.X_AXIS); bottomPane.add(bottomPane.createHorizontalGlue()); JButton abortButton = new JButton(Config.getWindowAbortButton()); abortButton.setMnemonic(Config.getWindowAbortMnemonic()); bottomPane.add(abortButton); bottomPane.add(bottomPane.createHorizontalGlue()); bottomPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); // Center Pane Box centerPane = new Box(BoxLayout.Y_AXIS); JLabel hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); _stepLabels = new JLabel[5]; for (int i = 0; i < _stepLabels.length; i++) { _stepLabels[i] = new JLabel(Config.getWindowStep(i)); _stepLabels[i].setEnabled(false); centerPane.add(_stepLabels[i]); // install label's length will expand,so set a longer size. if (i == STEP_INSTALL) { Dimension dim = new JLabel(Config.getWindowStepWait(STEP_INSTALL)).getPreferredSize(); _stepLabels[i].setPreferredSize(dim); } } hidden = new JLabel(Config.getWindowHiddenLabel()); hidden.setVisible(false); centerPane.add(hidden); // Setup box layout cont.add(topPane, "North"); cont.add(westPane, "West"); cont.add(bottomPane, "South"); cont.add(centerPane, "Center"); _installerFrame.pack(); Dimension dim = _installerFrame.getSize(); // hard code to ensure title is completely visible on Sol/lin. if (dim.width < 400) { dim.width = 400; _installerFrame.setSize(dim); } Rectangle size = _installerFrame.getBounds(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); size.width = Math.min(screenSize.width, size.width); size.height = Math.min(screenSize.height, size.height); // Put window at 1/4, 1/4 of screen resoluion _installerFrame.setBounds( (screenSize.width - size.width) / 4, (screenSize.height - size.height) / 4, size.width, size.height); // Setup event listners _installerFrame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we) { installFailed("Window closed", null); } }); abortButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { installFailed("Abort pressed", null); } }); // Show window _installerFrame.show(); }
// ---------------------------------// SpriteAnimate() { // constructor // Load and track the images mediaTracker = new MediaTracker(this); // Get and track the background // image backGroundImage = Toolkit.getDefaultToolkit().getImage("background02.gif"); mediaTracker.addImage(backGroundImage, 0); // Get and track 6 images to use // for sprites gifImages[0] = Toolkit.getDefaultToolkit().getImage("redball.gif"); mediaTracker.addImage(gifImages[0], 0); gifImages[1] = Toolkit.getDefaultToolkit().getImage("greenball.gif"); mediaTracker.addImage(gifImages[1], 0); gifImages[2] = Toolkit.getDefaultToolkit().getImage("blueball.gif"); mediaTracker.addImage(gifImages[2], 0); gifImages[3] = Toolkit.getDefaultToolkit().getImage("yellowball.gif"); mediaTracker.addImage(gifImages[3], 0); gifImages[4] = Toolkit.getDefaultToolkit().getImage("purpleball.gif"); mediaTracker.addImage(gifImages[4], 0); gifImages[5] = Toolkit.getDefaultToolkit().getImage("orangeball.gif"); mediaTracker.addImage(gifImages[5], 0); // Block and wait for all images to // be loaded try { mediaTracker.waitForID(0); } catch (InterruptedException e) { System.out.println(e); } // end catch // Base the Frame size on the size // of the background image. // These getter methods return -1 if // the size is not yet known. // Insets will be used later to // limit the graphics area to the // client area of the Frame. int width = backGroundImage.getWidth(this); int height = backGroundImage.getHeight(this); // While not likely, it may be // possible that the size isn't // known yet. Do the following // just in case. // Wait until size is known while (width == -1 || height == -1) { System.out.println("Waiting for image"); width = backGroundImage.getWidth(this); height = backGroundImage.getHeight(this); } // end while loop // Display the frame setSize(width, height); setVisible(true); setTitle("Copyright 2001, R.G.Baldwin"); // Create and start animation thread animationThread = new Thread(this); animationThread.start(); // Anonymous inner class window // listener to terminate the // program. this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } // end constructor