Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Loading Images  (Read 1254 times)
0 Members and 1 Guest are viewing this topic.
Offline ikantor

Senior Newbie




Java Games Rock!


« Posted 2004-06-10 13:25:37 »

I'm having some trouble loading images into my game. The images are currently saved in the directory where my class files are located. I'm using Windows 2000. I call the ClassLoader.getResource() method and it returns a URL that looks something like this: "file:C:/_Work/.../image.gif". Is this a valid URL to pass to the javax.imageio.ImageIO.read function or does the URL have to be an actual http address. I'm not sure that the question makes sense, but can anyone explain how to load images in Java.

Regards,
Igor
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2004-06-10 13:29:51 »

Yes, you use getResource... paths with '/' instead of '\' and lowercase extensions and pass that over to ImageIO. And yes it works even if you put it into a jar file (it works in both cases image inside the jar and image outside).

What I don't understand. Why do you ask? You could have just tried it for yourself in the same time.

弾幕 ☆ @mahonnaiseblog
Offline ikantor

Senior Newbie




Java Games Rock!


« Reply #2 - Posted 2004-06-10 13:36:55 »

It still doesn’t work. When I attempt to load an image that I find on google images it works fine. But when I try to load them from my disk it (ImageIO) returns a null image. I use JBuilder so I put the image in the \classes directory. It (getResource) finds the image but when I pass the URL to ImageIO it still returns a null.

Regards,
Igor
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ikantor

Senior Newbie




Java Games Rock!


« Reply #3 - Posted 2004-06-10 14:06:55 »

OK, I made some progress. The problem arises when ImageIO calls the getImageReaders() method. I looked inside it but didn't understand what the problem was. Anyway, when it calls getImageReader() the method returns an empty Iterator. This is why it keeps returning null. What file formats does ImageIO support. I was using .gif and thought that it was supported. Can anyone help?

Regards,
Igor
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2004-06-10 15:42:50 »

>Can anyone help?

As long as you don't provide additional information - no.

try
{
//image loading
}
catch(Exception e)
{
e.printStackTrace();
}

Show us the stacktrace and print the url (wich you've created) and check it and so on.

Also have you already tried to run the programm without using JBuilder? (because JBuilder sucks big time and I won't be surprised if it breaks everything)

弾幕 ☆ @mahonnaiseblog
Offline ikantor

Senior Newbie




Java Games Rock!


« Reply #5 - Posted 2004-06-10 16:04:48 »

OK Cheesy,

I'm very sorry to have been wasting your time. oNyx you were absolutely right and your advice is worth gold. I can't stop smiling. :-D. I just spent the last 3 days of my summer break on a simple mistake.

When I was saving the images using Microsoft Paint, I would write the following into the name edit box: image.gif. However, I would forget to change the format to gif. Assuming that Microsoft would do so automatically. This was the problem.

Again I apologize for my last 3 posts. Hey at least I learned something in the process.

Regards,
Igor

PS: I'm really not stupid, just 15. So please don't hold my age and inattention to detail against me.


Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #6 - Posted 2004-06-10 17:07:03 »

Hehe. Well, that's just usual. You'll see that you waste the most time with really silly mistakes.

Just some days ago I wasted alot of time hunting a bug in my "snap to grid" method. Actually... everything was perfect there it was my text printing routine(!) wich reseted that opengl stuff and I had simply forgotten that - doh Smiley

Remember that the PC in 99.9999% of the cases exactly does that what you (or 3rd party apis) tell him to do. If there's a bug and the obvious places aren't the reason, check every single step carefully.

Oh and enable file extensions for the explorer - that avoids alot of confusion. It should be somewere under view->directory options (or so) and it's called "hide file extensions of known file types" (or so)... disable that and use the "details" view. It's much nicer then.

15 is a good age to start this stuff imo oh and excuse my manners - welcome to the board Wink

弾幕 ☆ @mahonnaiseblog
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (35 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!