• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

drawImage() problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you initializing the images in the paintComponent method?
Typically they are initialized in the constructor.
Also take a look at the MediaTracker class.
 
Edmond Corrola
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How big is the image?
Does it work if you paint the image directly instead of the buffered image?
 
Edmond Corrola
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic