微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,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,null);
        return bufImage;
    }
}
项目:openjdk9    文件MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image)
    throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image,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,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,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,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,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,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,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,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,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",1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
项目:jvm-stm    文件ImageViewer.java   
public void setCommandContext(String verb,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)));
}
项目: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,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,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,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,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,null);
        return bufImage;
    }
}
项目:jdk8u-dev-jdk    文件MultiResolutionImageTest.java   
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image,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,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 @R_840_4045@ion 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,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()),mode));
                    return false;
                }
                return true;
            }
        });
//        this.setimage(this.getimage().getScaledInstance(largeur,Image.SCALE_SMOOTH));
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。