How can I load an image into a BufferedImage without creating a Component for the MediaTracker?

Bruno Randolf

You can achieve this by using an ImageIcon:


private BufferedImage loadBufferedImageIcon( String filename )
{
  // Get Image
  ImageIcon icon = new ImageIcon(filename);
  Image image = icon.getImage();

  // Create empty BufferedImage, sized to Image
  BufferedImage buffImage = 
    new BufferedImage(
    image.getWidth(null), 
    image.getHeight(null), 
    BufferedImage.TYPE_INT_RGB);
	
  // Draw Image into BufferedImage
  Graphics g = buffImage.getGraphics();
  g.drawImage(image, 0, 0, null);

  return buffImage;
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact