I have to show a bmp image in a Canvas, inside a frame. I tried to use Toolkit's getImage(String <filename> , but it didn't work... Actually I copied the code from an old post here at this forum. Here it is:
It compiles and run fine, but the image simply is not painted, and it actually exists (i get a true printed in the console). Why doesn't it work? How can it be done (without using an applet) ? Thanks in advance... JUBA d-_-b
Amanda Weber
Greenhorn
Joined: Nov 20, 2002
Posts: 28
posted
0
The drawImage method of the graphics class returns a boolean if the image displayed. Try using it in a while loop: while (!g.drawImage(......)) repaint;
Jonathas Carrijo
Greenhorn
Joined: Jul 25, 2002
Posts: 25
posted
0
I changed the paint() method as follows:
And all I got is hundreds of thousands of: drawImage: false drawImage: false drawImage: false drawImage: false drawImage: false Why??? What can be done? I really need this working! Please help me... Thanks, Juba d-_-b
Amanda Weber
Greenhorn
Joined: Nov 20, 2002
Posts: 28
posted
0
You are trying to draw the image before it is fully loaded. Use the MediaTracker to get when the image will be loaded, then draw it. Sun's documentation on java.awt.MediaTracker explains it very well.
Jonathas Carrijo
Greenhorn
Joined: Jul 25, 2002
Posts: 25
posted
0
I added this to my code. Everything compiled and ran fine, but still didn't show my image...
I got as output: Error loading: true which means that there was an error loading the image... I tried to use the getImage() method which takes an URL as parameter, like this:
instead of the tk.getImage("c:\\juba\\used.bmp"); Didn`t work yet... I think I'm gonna migrate to Swing... or even to C# (hehehe) Am I attacking it the right way? I mean, is the problem actually in the path specification? Anybody help, I need it deployed till tomorrow... Thanks much! Juba d-_-b [ November 21, 2002: Message edited by: Jonathas Carrijo ]
Jonathas Carrijo
Greenhorn
Joined: Jul 25, 2002
Posts: 25
posted
0
Please guys... I really need help on this! Haven't anybody ever had a happy experience loading images?? Please share with me Thanks a lot
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Try this. Note that Balloon.jpg is in the same directory with ImageFrame.class.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Did you notice the thread was labelled urgent? I hope ten years wasn’t too long to wait That tutorial might not even have been available in 2002!
It was urgent for me too. I couln't find anything of value except this, and I thought it wold be valuable information for other people who find this forum as well.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32718
4
posted
0
Yes, it is valuable information. Thank you, It is just that we sometimes wonder whether people realise they are reopening such old threads.