dcsimg
2-D image not loading properly into a GUI
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dennis_Bergau
Posted On:   Monday, April 16, 2001 11:41 PM

I am trying to get an image (.gif, .jpg, etc...) to load into a BufferedImage object and display this in a Graphics2D field. I am getting the image to show up vertically, but only a small part of the horizontal portion of the picture will show up. My code looks like this: public void loadImage(String name) { Image loadedImage = Toolkit.getDefaultToolkit().getImage( name ); MediaTracker tracker = new MediaTracker(this); tracker.addImage( loadedImage, 0, 300, 300 ); try { tracker.waitForID(0); } catch (InterruptedException e) {} image = new BufferedImage(loadedImage.getWidth(null), loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics();   More>>

I am trying to get an image (.gif, .jpg, etc...) to load into a BufferedImage object and display this in a Graphics2D field. I am getting the image to show up vertically, but only a small part of the horizontal portion of the picture will show up. My code looks like this:


public void loadImage(String name)
{
Image loadedImage = Toolkit.getDefaultToolkit().getImage( name );
MediaTracker tracker = new MediaTracker(this);
tracker.addImage( loadedImage, 0, 300, 300 );
try { tracker.waitForID(0); }
catch (InterruptedException e) {}
image = new BufferedImage(loadedImage.getWidth(null),
loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
g2.drawImage(loadedImage, 0, 0, null );

repaint();
}


I have played around with the addImage() and drawImage() methods but I have not had much luck. Does anyone have any suggestions?

Thanks!!!
Dennis

   <<Less
About | Sitemap | Contact