• Post Reply Bookmark Topic Watch Topic
  • New Topic

load image using mediatracker

 
pavan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using mediatracker in loading image.


try {

MediaTracker tracker = new MediaTracker(null);

while(i<=filenames.length-1) {

Image im = Toolkit.getDefaultToolkit().getImage("D:/photos/thumb/"+filenames[i]);



tracker.addImage(im,i);



tracker.waitForID(i);


width=im.getWidth(null);
height=im.getHeight(null);

}
}catch(Exception e) { out.println(e.getMessage()); }


but it gived error : null


where is problem?
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pavan sharma:

MediaTracker tracker = new MediaTracker(null);


This is no good. If you intend to use the tracker for anything you must pass in an actual Component (or JComponent) to the constructor.
 
pavan sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I got another way - and it return actual width and height in first time.

BufferedImage image = ImageIO.read(new URL("http://today.java.net/jag/bio/JagHeadshot.jpg"));

int w = image.getWidth(); //if you want...
int h = image.getHeight();//if you want.



Thanks,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!