List of usage examples for java.awt MediaTracker waitForAll
public void waitForAll() throws InterruptedException
From source file:com.tomtom.speedtools.json.ImageSerializer.java
@Nonnull private static BufferedImage convertToBufferedImage(@Nonnull final Image image) throws IOException { assert image != null; if (image instanceof BufferedImage) { return (BufferedImage) image; }/* w ww . j ava2 s. c om*/ /** * Load the image in the background and wait * until is is downloaded. */ final MediaTracker tracker = new MediaTracker(new Component() { // Empty. }); tracker.addImage(image, 0); try { tracker.waitForAll(); } catch (final InterruptedException e) { throw new IOException(e.getMessage(), e); } /** * Create a buffered image with the right dimensions. */ final BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); /** * Draw the image in the buffer and return it as base64 data. */ final Graphics g = bufImage.createGraphics(); g.drawImage(image, 0, 0, null); return bufImage; }
From source file:BufferedImageMouseDrag.java
DisplayCanvas() { setBackground(Color.white);/*from ww w . j ava 2 s . com*/ setSize(450, 400); addMouseMotionListener(new MouseMotionHandler()); Image image = getToolkit().getImage("largeJava2sLogo.gif"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("no gif file"); System.exit(0); } bi = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); big.drawImage(image, 0, 0, this); }
From source file:Main.java
ContentPanel() { MediaTracker mt = new MediaTracker(this); bgimage = Toolkit.getDefaultToolkit().getImage("a.jpg"); mt.addImage(bgimage, 0);// ww w .j ava 2 s.co m try { mt.waitForAll(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:FilterLab.java
public void init() { originalImage = getImage(getDocumentBase(), "e.gif"); MediaTracker tracker = new MediaTracker(this); tracker.addImage(originalImage, 0);/* w ww . j a v a 2 s . c o m*/ try { tracker.waitForAll(); } catch (Exception e) { } filteredImage = originalImage; btn.addActionListener(this); add(btn); }
From source file:AttributesApp.java
public void loadImage() { image = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.gif"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1);// www . j av a 2s.c om try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading."); } if (image.getWidth(this) == -1) { System.out.println("no images"); System.exit(0); } }
From source file:FilterLab.java
public void init() { originalImage = getImage(getDocumentBase(), "emily.gif"); MediaTracker tracker = new MediaTracker(this); tracker.addImage(originalImage, 0);/*from w ww . j a v a 2 s .c o m*/ try { tracker.waitForAll(); } catch (Exception e) { } filteredImage = originalImage; btn.addActionListener(this); add(btn); }
From source file:MainClass.java
public void init() { MediaTracker mt = new MediaTracker(this); i = getImage(getDocumentBase(), "rosey.jpg"); mt.addImage(i, 0);//from ww w . j av a2s .c o m try { mt.waitForAll(); int width = i.getWidth(this); int height = i.getHeight(this); j = createImage(new FilteredImageSource(i.getSource(), new CropImageFilter(width / 3, height / 3, width / 3, height / 3))); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:RasterDemo.java
RasterPanel() { setBackground(Color.white);// w w w .ja v a 2 s . c o m setSize(450, 400); Image image = getToolkit().getImage("largeJava2sLogo.jpg"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("No jpg file"); System.exit(0); } bi1 = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi1.createGraphics(); big.drawImage(image, 0, 0, this); bi = bi1; }
From source file:ColorConvertDemo.java
public void loadImage() { displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg"); MediaTracker mt = new MediaTracker(this); mt.addImage(displayImage, 1);//from w ww. j a v a 2 s . c o m try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading."); } if (displayImage.getWidth(this) == -1) { System.out.println("No jpg "); System.exit(0); } }
From source file:SimpleBufferedImageDemo.java
DisplayCanvas() { displayImage = Toolkit.getDefaultToolkit().getImage("largeJava2sLogo.jpg"); MediaTracker mt = new MediaTracker(this); mt.addImage(displayImage, 1);/* w ww. j a v a 2 s . c o m*/ try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading."); } if (displayImage.getWidth(this) == -1) { System.out.println("No *.jpg file"); System.exit(0); } setBackground(Color.white); setSize(400, 225); }