Java 类java.awt.MediaTracker 实例源码

项目:OpenJSharp    文件:RuntimeBuiltinLeafInfoImpl.java   
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        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_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
项目:jdk8u-jdk    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
项目:openjdk-jdk10    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);

    testImageLoaded(image);

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    Image resolutionVariant = ((MultiResolutionImage) image)
        .getResolutionVariant(2 * w, 2 * h);

    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }

    testImageLoaded(resolutionVariant);
}
项目:openjdk-jdk10    文件:RuntimeBuiltinLeafInfoImpl.java   
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        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_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
项目:openjdk9    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);

    testImageLoaded(image);

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    Image resolutionVariant = ((MultiResolutionImage) image)
        .getResolutionVariant(2 * w, 2 * h);

    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }

    testImageLoaded(resolutionVariant);
}
项目:openjdk9    文件:RuntimeBuiltinLeafInfoImpl.java   
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        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_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
项目:OpenNFMM    文件:xtGraphics.java   
static private void loadimages() {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final MediaTracker mediatracker = new MediaTracker(app);
    dnload += 8;
    try {
        for (int i = 0; i < idts.length; i++) {
            idts[i].cons.accept(Files.readAllBytes(new File(Madness.fpath + "data/images/" + idts[i].fileName).toPath()), mediatracker, toolkit);
        }

        dnload += 2;

    } catch (final Exception exception) {
        System.err.println("Error Loading Images: " + exception);
    }
    System.gc();
}
项目:PhET    文件:ImageLoader.java   
public Image fetchImage( URL imageLocation ) throws IOException {
    Image image = null;
    try {
        if ( imageLocation == null ) {
            throw new IOException( "Image resource not found: Null imagelocation URL" );
        }
        else {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            image = toolkit.createImage( imageLocation );
            MediaTracker tracker = new MediaTracker( this );
            tracker.addImage( image, 0 );
            tracker.waitForAll();
        }
    }
    catch ( InterruptedException e ) {
    }
    return image;
}
项目:PhET    文件:AppletLoader.java   
/**
 * Get Image from path provided
 *
 * @param url location of the image
 * @return the Image file
 */
public Image getImage(URL url) {
    try {
        MediaTracker tracker = new MediaTracker(this);

        Image image = super.getImage(url);

        // wait for image to load
        tracker.addImage(image, 0);
        tracker.waitForAll();

        // if no errors return image
        if (!tracker.isErrorAny()) {
            return image;
        }
    } catch (Exception e) {
        /* */
    }

    return null;
}
项目:PhET    文件:Viewer.java   
public Image getFileAsImage(String pathName, String[] retFileNameOrError) {
  if (!haveDisplay) {
    retFileNameOrError[0] = "no display";
    return null;
  }
  Image image = fileManager.getFileAsImage(pathName, retFileNameOrError);
  if (image == null)
    return null;
  MediaTracker tracker = new MediaTracker(display);
  tracker.addImage(image, 0);
  try {
    tracker.waitForID(0);
  } catch (InterruptedException e) {
    // Got to do something?
  }
  return image;
}
项目:jasperreports    文件:JasperApp.java   
/**
 *
 */
public void run() throws JRException
{
    long start = System.currentTimeMillis();
    //Preparing parameters
    Image image = Toolkit.getDefaultToolkit().createImage("dukesign.jpg");
    MediaTracker traker = new MediaTracker(new Panel());
    traker.addImage(image, 0);
    try
    {
        traker.waitForID(0);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ReportTitle", "The First Jasper Report Ever");
    parameters.put("MaxOrderID", new Integer(10500));
    parameters.put("SummaryImage", image);

    JasperRunManager.runReportToPdfFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
    System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
}
项目:JSmooth    文件:Splash.java   
public Splash(Frame parent, String imagefilename, boolean dialog)
   {
if (dialog)
    {
               m_window = new MyDialog(parent);
    }
else
    {
               m_window = new MyWindow(parent);
    }
javax.swing.ImageIcon icon = new javax.swing.ImageIcon(getClass().getResource(imagefilename));
m_splashImage = icon.getImage();
MediaTracker loader = new MediaTracker(m_window);
loader.addImage(m_splashImage, 0);
try { 
           loader.waitForAll(); 
} catch (Exception e) {}
   }
项目:jdk8u_jdk    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }
    tracker.removeImage(image, 0);

    testImageLoaded(image);

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    Image resolutionVariant = ((MultiResolutionImage) image)
        .getResolutionVariant(2 * w, 2 * h);

    if (image == resolutionVariant) {
        throw new RuntimeException("Resolution variant is not loaded");
    }

    testImageLoaded(resolutionVariant);
}
项目:lookaside_java-1.8.0-openjdk    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
项目:lookaside_java-1.8.0-openjdk    文件:RuntimeBuiltinLeafInfoImpl.java   
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        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_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
项目:LS-jsampler    文件:AudioDevicesPage.java   
DuplicateAudioDevice() {
    super("");

    putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDuplicateAudioDevice"));

    try {
        URL url = ClassLoader.getSystemClassLoader().getResource (
            "org/jsampler/view/classic/res/icons/Copy16.gif"
        );

        ImageIcon icon = new ImageIcon(url);
        if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
            putValue(Action.SMALL_ICON, icon);
    } catch(Exception x) {
        CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
    }

    setEnabled(false);
}
项目:LS-jsampler    文件:AudioDevicesPage.java   
RemoveAudioDevice() {
    super("");

    putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRemoveAudioDevice"));

    try {
        URL url = ClassLoader.getSystemClassLoader().getResource (
            "org/jsampler/view/classic/res/icons/Delete16.gif"
        );

        ImageIcon icon = new ImageIcon(url);
        if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
            putValue(Action.SMALL_ICON, icon);
    } catch(Exception x) {
        CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
    }

    setEnabled(false);
}
项目:LS-jsampler    文件:AudioDevicesPage.java   
AudioDeviceProps() {
    super("");

    putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAudioDeviceProps"));

    try {
        URL url = ClassLoader.getSystemClassLoader().getResource (
            "org/jsampler/view/classic/res/icons/Properties16.gif"
        );

        ImageIcon icon = new ImageIcon(url);
        if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
            putValue(Action.SMALL_ICON, icon);
    } catch(Exception x) {
        CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x);
    }

    setEnabled(false);
}
项目:javify    文件:ImageViewer.java   
public void setCommandContext(String verb, DataHandler dh)
  throws IOException
{
  // Read image into a byte array
  InputStream in = dh.getInputStream();
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  byte[] buf = new byte[4096];
  for (int len = in.read(buf); len != -1; len = in.read(buf))
    bytes.write(buf, 0, len);
  in.close();
  // Create and prepare the image
  Toolkit toolkit = getToolkit();
  Image img = toolkit.createImage(bytes.toByteArray());
  try
    {
      MediaTracker tracker = new MediaTracker(this);
      tracker.addImage(img, 0);
      tracker.waitForID(0);
    }
  catch (InterruptedException e)
    {
    }
  toolkit.prepareImage(img, -1, -1, this);
}
项目:code-similarity    文件:Bounce.java   
public void init() {
    Button b = new Button("Start");
    b.addActionListener(this);
    setLayout(new BorderLayout());
    add(b, BorderLayout.NORTH);
    add(p = new Panel(), BorderLayout.CENTER);
    p.setLayout(null);
    String imgName = getParameter("imagefile");
    if (imgName == null) imgName = "duke.gif";
    img = getImage(getCodeBase(), imgName);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(img, 0);
    try {
        mt.waitForID(0);
    } catch(InterruptedException e) {
        throw new IllegalArgumentException(
            "InterruptedException while loading image " + imgName);
    }
    if (mt.isErrorID(0)) {
        throw new IllegalArgumentException(
            "Couldn't load image " + imgName);
    }
    v = new Vector<Sprite>(); // multithreaded, use Vector
}
项目:mars-sim    文件:CannedMarsMap.java   
/** 
 * Creates a 2D map at a given center point.
 * @param newCenter the new center location
 */
public void drawMap(Coordinates newCenter) {
    if ((newCenter != null) && (!newCenter.equals(currentCenter))) {
        mapImage = createMapImage(newCenter);

        MediaTracker mt = new MediaTracker(displayArea);
        mt.addImage(mapImage, 0);
        try {
            mt.waitForID(0);
        } 
        catch (InterruptedException e) {
            logger.log(Level.SEVERE,Msg.getString("CannedMarsMap.log.mediaTrackerInterrupted") + e); //$NON-NLS-1$
        }
        mapImageDone = true;
        currentCenter = new Coordinates(newCenter);
    }
}
项目:triplea    文件:ReliefImageBreaker.java   
/**
 * Asks the user to select an image and then it loads it up into an Image
 * object and returns it to the calling class.
 *
 * @return java.awt.Image img the loaded image
 */
private static Image loadImage() {
  System.out.println("Select the map");
  final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
项目:triplea    文件:TileImageBreaker.java   
/**
 * java.awt.Image loadImage()
 * Asks the user to select an image and then it loads it up into an Image
 * object and returns it to the calling class.
 *
 * @return java.awt.Image img the loaded image
 */
private static Image loadImage() {
  System.out.println("Select the map");
  final String mapName = new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
项目:jvm-stm    文件:ImageViewer.java   
public void setCommandContext(String verb, DataHandler dh)
  throws IOException
{
  // Read image into a byte array
  InputStream in = dh.getInputStream();
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  byte[] buf = new byte[4096];
  for (int len = in.read(buf); len != -1; len = in.read(buf))
    bytes.write(buf, 0, len);
  in.close();
  // Create and prepare the image
  Toolkit toolkit = getToolkit();
  Image img = toolkit.createImage(bytes.toByteArray());
  try
    {
      MediaTracker tracker = new MediaTracker(this);
      tracker.addImage(img, 0);
      tracker.waitForID(0);
    }
  catch (InterruptedException e)
    {
    }
  toolkit.prepareImage(img, -1, -1, this);
}
项目:chatty    文件:GifUtil.java   
/**
 * Loads a GIF from the given URL, fixing FPS, or just creates an ImageIcon
 * directly if it's not a valid GIF.
 * 
 * @param url The URL (local or internet) to get the image data from
 * @return The created ImageIcon, or null if an error occured creating the
 * image
 * @throws Exception When an error occured loading the image
 */
public static ImageIcon getGifFromUrl(URL url) throws Exception {
    try (InputStream input = url.openStream()) {
        // Use readAllBytes() because GifDecoder doesn't handle streams well
        byte[] imageData = readAllBytes(input);
        ImageIcon image = null;
        try {
            //System.out.println(hash(imageData)+" "+url);
            image = fixGifFps(imageData);
        } catch (Exception ex) {
            /**
             * If not a GIF, or another error occured, just create the image
             * normally.
             */
            image = new ImageIcon(imageData);
        }

        if (image.getImageLoadStatus() == MediaTracker.ERRORED) {
            return null;
        }
        return image;
    }
}
项目:xdat    文件:CustomButton.java   
/**
 * Instantiates a new custom button.
 * 
 * @param toolTip
 *            the message that is displayed when hovering over the button
 *            with the mouse.
 * @param pathToDefaultImage
 *            the path to image representing the unpressed state of the
 *            button.
 * @param pathToPressedImage
 *            the path to image representing the pressed state of the
 *            button.
 * @param actionCommand
 *            the action command
 */
public CustomButton(String toolTip, String pathToDefaultImage, String pathToPressedImage, String actionCommand) {
    super();
    this.setToolTipText(toolTip);
    URL urlDefault = Main.class.getResource(pathToDefaultImage);
    URL urlPressed = Main.class.getResource(pathToPressedImage);

    this.imgDefault = null;
    this.imgPressed = null;
    Toolkit tk = Toolkit.getDefaultToolkit();
    try {
        MediaTracker m = new MediaTracker(this);
        this.imgDefault = tk.getImage(urlDefault);
        m.addImage(this.imgDefault, 0);
        this.imgPressed = tk.getImage(urlPressed);
        m.addImage(this.imgPressed, 0);
        m.waitForAll();
    } catch (Exception e) {
        e.printStackTrace();
    }

    // }
    this.setActionCommand(actionCommand);
    this.setLayout(new GridLayout(1, 1));
    this.setPreferredSize(new Dimension(imgDefault.getWidth(this), imgDefault.getHeight(this)));
}
项目:OpenNFMM    文件:xtGraphics.java   
static private void loadimages() {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final MediaTracker mediatracker = new MediaTracker(app);
    dnload += 8;
    try {
        for (int i = 0; i < idts.length; i++) {
            idts[i].cons.accept(Files.readAllBytes(new File(Madness.fpath + "data/images/" + idts[i].fileName).toPath()), mediatracker, toolkit);
        }

        dnload += 2;

    } catch (final Exception exception) {
        System.err.println("Error Loading Images: " + exception);
    }
    System.gc();
}
项目:metasfresh    文件:Attachment.java   
/**
 * Set Image
 * 
 * @param image image
 */
public void setImage(final Image image)
{
    m_image = image;
    if (m_image == null)
        return;

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(m_image, 0);
    try
    {
        mt.waitForID(0);
    }
    catch (Exception e)
    {
    }
    Dimension dim = new Dimension(m_image.getWidth(this), m_image.getHeight(this));
    this.setPreferredSize(dim);
}
项目:graphwar    文件:GraphPlane.java   
private void initializeDeaths(Graphwar graphwar, MediaTracker mediaTracker) throws Exception
{       
    String filePath = "/rsc/soldierDeath.txt";

    BufferedReader read =  new BufferedReader(new InputStreamReader(graphwar.getClass().getResourceAsStream(filePath)));

    int numImages = Integer.parseInt(GraphUtil.nextLine(read).trim());
    deathImages = new Image[numImages];
    deathDurations = new int[numImages];

    for(int j=0; j<numImages;j++)
    {   
        deathImages[j] = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
        deathDurations[j] = Integer.parseInt(GraphUtil.nextLine(read).trim());
        mediaTracker.addImage(deathImages[j], 0);
    }

    deathFadeDuration = Integer.parseInt(GraphUtil.nextLine(read).trim());
}
项目:graphwar    文件:GraphPlane.java   
private void initializeExplosions(Graphwar graphwar, MediaTracker mediaTracker) throws Exception
{       
    String filePath = "/rsc/explosion.txt";

    BufferedReader read =  new BufferedReader(new InputStreamReader(graphwar.getClass().getResourceAsStream(filePath)));

    int numImages = Integer.parseInt(GraphUtil.nextLine(read).trim());
    explosionImages = new Image[numImages];
    explosionDurations = new int[numImages];

    for(int j=0; j<numImages;j++)
    {   
        explosionImages[j] = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
        explosionDurations[j] = Integer.parseInt(GraphUtil.nextLine(read).trim());
        mediaTracker.addImage(explosionImages[j], 0);
    }

}
项目:graphwar    文件:GraphUtil.java   
public static JLabel makeBackgroundImage(Graphwar graphwar, BufferedReader read) throws InterruptedException, IOException
{
    MediaTracker tracker = new MediaTracker(graphwar);

    Image image = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));  
    tracker.addImage(image, 0);     
    tracker.waitForAll();       

    int x = Integer.parseInt(GraphUtil.nextLine(read));
    int y = Integer.parseInt(GraphUtil.nextLine(read));

    JLabel imagePanel = new JLabel(new ImageIcon(image));
    imagePanel.setBounds(x, y, image.getWidth(null), image.getHeight(null));

    return imagePanel;

}
项目:graphwar    文件:GraphUtil.java   
public static GraphButton makeButton(Graphwar graphwar, BufferedReader read) throws InterruptedException, IOException
{
    MediaTracker tracker = new MediaTracker(graphwar);

    Image normal = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
    tracker.addImage(normal, 0);
    Image over = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
    tracker.addImage(over, 1);
    Image tempImg = ImageIO.read(graphwar.getClass().getResource(GraphUtil.nextLine(read)));
    tracker.addImage(tempImg, 2);
    tracker.waitForAll();


    BufferedImage mask = new BufferedImage(tempImg.getWidth(null), tempImg.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);          
    mask.getGraphics().drawImage(tempImg, 0, 0, null);

    int x = Integer.parseInt(GraphUtil.nextLine(read));
    int y = Integer.parseInt(GraphUtil.nextLine(read));

    GraphButton graphButton = new GraphButton(normal, over, mask);
    graphButton.setBounds(x, y, normal.getWidth(null), normal.getWidth(null));

    return graphButton;
}
项目:Chatty-Twitch-Client    文件:Emoticon.java   
@Override
protected ImageIcon doInBackground() throws Exception {
    ImageIcon icon = loadEmote();

    /**
     * If an error occured, return null.
     */
    if (icon == null) {
        return null;
    }
    /**
     * Only doing this on ERRORED, waiting for COMPLETE would not allow
     * animated GIFs to load
     */
    if (icon.getImageLoadStatus() == MediaTracker.ERRORED) {
        icon.getImage().flush();
        return null;
    }
    if (icon.getIconWidth() > width || icon.getIconHeight() > height) {
        LOGGER.warning("Scaled emote: "+code+" ("+icon.getIconWidth()+"x"
                +icon.getIconHeight()+" -> "+width+"x"+height+")");
        Image scaled = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
        icon.setImage(scaled);
    }
    return icon;
}
项目:infobip-open-jdk-8    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
项目:infobip-open-jdk-8    文件:RuntimeBuiltinLeafInfoImpl.java   
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        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_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
项目:jdk8u-dev-jdk    文件:MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
项目:aibench-project    文件:Util.java   
public static void startSplashScreen() {
        int width = 275, height = 148;
        Window win = new Window(new Frame());
        win.pack();
        BshCanvas can = new BshCanvas();
        can.setSize(width, height); // why is this necessary?
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension dim = tk.getScreenSize();
        win.setBounds(dim.width / 2 - width / 2, dim.height / 2 - height / 2, width, height);
        win.add("Center", can);
        Image img = tk.getImage(Interpreter.class.getResource("/bsh/util/lib/splash.gif"));
        MediaTracker mt = new MediaTracker(can);
        mt.addImage(img, 0);
        try {
                mt.waitForAll();
        } catch (Exception e) {
        }
        Graphics gr = can.getBufferedGraphics();
        gr.drawImage(img, 0, 0, can);
        win.setVisible(true);
        win.toFront();
        splashScreen = win;
}
项目:openbd-core    文件:JpegEncoder.java   
public JpegEncoder(Image image, int quality, OutputStream out) {
    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;
    outStream = new BufferedOutputStream(out);
    dct = new DCT(Quality);
    Huf = new Huffman(imageWidth, imageHeight);
}
项目:MathEOS    文件:ImageTools.java   
/**
 * Méthode qui convertit une image en BufferedImage.
 *
 * @param im l'image à convertir
 * @return une BufferedImage créée à partir de l'image passée en paramètre
 */
public static BufferedImage imageToBufferedImage(Image im) {
    if(im==null) {return null;}
    if(im instanceof BufferedImage) {return (BufferedImage) im;}//On tente un simple Cast
    //On vérifie que l'image est bien chargée
    if(im.getWidth(null)==-1 || im.getHeight(null)==-1) {
        MediaTracker tracker = new MediaTracker(new Component(){});
        tracker.addImage(im, 0);
        try {
            tracker.waitForID(0);
        } catch (InterruptedException ex1) {
            Logger.getLogger(ImageTools.class.getName()).log(Level.SEVERE, null, ex1);
            if(im.getWidth(null)==-1 || im.getHeight(null)==-1) return null;
        }
    }
    //On dessine l'image dans un buffer
    BufferedImage bi = new BufferedImage(im.getWidth(null), im.getHeight(null), BufferedImage.TYPE_4BYTE_ABGR);
    Graphics bg = bi.createGraphics();
    bg.drawImage(im, 0, 0, null);
    bg.dispose();
    return bi;
}
项目:MathEOS    文件:Icone.java   
private void setScaledImage(final int largeur, final int hauteur, final Scalr.Mode mode) {
        if(largeur<=0 || hauteur<=0) return;
        if(this.getImageLoadStatus()==MediaTracker.COMPLETE) {
            if(largeurInitiale<=0) {largeurInitiale=this.getIconWidth();}
            if(hauteurInitiale<=0) {hauteurInitiale=this.getIconHeight();}
            this.setImage(ImageTools.getScaledInstance(ImageTools.imageToBufferedImage(this.getImage()), largeur, hauteur, ImageTools.Quality.OPTIMAL, mode));
        }
        getImage().getWidth(new ImageObserver() {
            @Override
            public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
                if((infoflags & ALLBITS)!=0) {
                    if(Icone.this.largeurInitiale<=0) {Icone.this.largeurInitiale=Icone.this.getIconWidth();}
                    if(Icone.this.hauteurInitiale<=0) {Icone.this.hauteurInitiale=Icone.this.getIconHeight();}
                    Icone.this.setImage(ImageTools.getScaledInstance(ImageTools.imageToBufferedImage(Icone.this.getImage()), largeur, hauteur, ImageTools.Quality.OPTIMAL, mode));
                    return false;
                }
                return true;
            }
        });
//        this.setImage(this.getImage().getScaledInstance(largeur, hauteur, Image.SCALE_SMOOTH));
    }