Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: How do you best handle incomplete image loading

  1. #1
    Junior Member
    Join Date
    Jan 2022
    Posts
    20
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default How do you best handle incomplete image loading

    I am loading an Image resource then converting it to BufferedImage but the conversion routine uses the images width and height and until the image is fully loaded these return -1.
    I use a while loop to wait but this doesn't seem the best way to do it.
    private Image loadCardsTileSet(){   
            try{ 
                Image image = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(Engine.CARDS_TILESET_FILEPATH));
                while(image.getWidth(null)==-1){}
                BufferedImage img = Engine.toBufferedImage(image);
    Is there a better way?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How do you best handle incomplete image loading

    Try the ImageIO class's read method.

    If you want to keep the existing code, look at the MediaTracker class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Loading an image in ImageView through code javafx
    By viper_pranish in forum JavaFX
    Replies: 0
    Last Post: January 19th, 2014, 05:02 AM
  2. [SOLVED] Image not loading
    By Bebras in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: January 10th, 2014, 05:36 PM
  3. Problems With Image Loading and Extended Objects
    By Gravity Games in forum Object Oriented Programming
    Replies: 13
    Last Post: April 22nd, 2013, 01:31 PM
  4. loading my image
    By riddick_charel in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 26th, 2013, 06:12 AM
  5. ImageIcon Erratically Loading URL Image
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 3rd, 2011, 04:05 PM