• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert image to bufferedImage

 
Sandy Abraham
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an error when i try to convert my image to a buffered image, so that I can getRaster().
My code is:
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage("Image2.jpg");
BufferedImage sourceBufferedImage =new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_ARGB);
The error is :
Exception in thread "main" java.lang.IllegalArgumentException: Width (-1) and he
ight (-1) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Direct
ColorModel.java:999)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:259)
at Joan$MyCanvas.<init>(Joan.java:67)
at Joan.setupPanels(Joan.java:115)
at Joan.<init>(Joan.java:92)
at Joan.main(Joan.java:100)

What is the problem? Please help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!