Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: James Rivera   on Feb 24 In Java Category.

  
Question Answered By: Fabia Ferrrari   on Feb 24

try change your code  in method load  to :


public void  load()
{
paintComponents(image_panel.getGraphics());
// the argument is a graphics from panel object
}

public void paintComponents ( Graphics g )
{
//img =
Toolkit.getDefaultToolkit().getImage("Splash.jpg");
img =
Toolkit.getDefaultToolkit().createImage(this.getClass().getResource("Splash.jpg"\
));
System.out.println ("Image Loaded" );

try
{
MediaTracker mediaTracker = new MediaTracker(
new
Container() );
mediaTracker.addImage ( img  , 0 ) ;
mediaTracker.waitForID( 0 ) ;
}
catch ( Exception ex )
{}

int imageWidth = img.getWidth( null ) ;
int imageHeight = img.getHeight ( null );
g.drawImage(img,0,0,imageWidth,imageHeight,null);

/* I don't know what the rest of your code for, but from
this code (
g.drawImage(img,0,0,imageWidth,imageHeight,null);
the image  already loaded..

BufferedImage thumbnail = new BufferedImage (
imageWidth ,
imageHeight , BufferedImage.TYPE_INT_RGB ) ;

Graphics2D graphics2d = ( Graphics2D ) g ;

graphics2d = thumbnail.createGraphics();

graphics2d.setRenderingHint(
RenderingHints.KEY_INTERPOLATION ,
RenderingHints.VALUE_INTERPOLATION_BILINEAR );

graphics2d.drawImage ( img , 0 , 0 ,
imageWidth , imageHeight , this );*/

}

Share: 

 
 
Didn't find what you were looking for? Find more on trying to load the image in a JPanel Or get search suggestion and latest updates.


Tagged: