This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Trying to load an image from file and draw it in a JPanel. Just seems to draw a black rectangle instead of the image.
It's a gray scale image, so I thought I could use BufferedImage.TYPE_BYTE_GRAY, i'm not going to be working in color anyway. I will just be lowering the gray scale value from 256 down and evaluating image quality.
Thanks in advance for any help.
[ November 06, 2008: Message edited by: Edmond Corrola ] [ November 07, 2008: Message edited by: Edmond Corrola ]
Not really looking for anything complicated (media tracker class). Just want to load an image from file and display it on a Jpanel and be able to modify the buffer. As for the initializing, I can swap it into the constructor no problem. Still have the same issue though (I originally had it that way anyway). It's only a couple lines of code to display an image and I don't see what's wrong with it...Do you have any ideas why it won't display an image from file as it is now? Is it because I'm loading the image from file into a buffered image, should it be done this way instead:
Load image to "Image" object Create BufferedImage same size as image Create a graphics object from the BufferedImage Draw Image onto graphics object (essentially populating my once empty buffered image)
Is this the logical way to do it? [ November 07, 2008: Message edited by: Edmond Corrola ]
How big is the image? Does it work if you paint the image directly instead of the buffered image?
Joined: May 23, 2008
I know what's wrong now. I decided to make use of two graphics objects, one that belongs to the panel in order to display the image. And the other one I associated with my buffered image, so when I draw the image onto it, it gets stored in the buffered image as well. I just wasn't thinking clearly before. So two graphics objects with the image drawn onto it, while one graphics object has an associated buffered image.