• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why doesn't the image appear with this code.

 
Adam Miszczak
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I decided to to a bit of training with 2D and wanted to draw an image on screen. I followed a tutorial and wrote the code, however the image does not appear.
It does not throw up an error or anything, it just displays the window and the image does not appear.

image class:



screen class:



Thank you!!!
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Things could have changed since the last time I dealt with this sort of thing, but BMP never used to be a supported format for images in Java.
 
Adam Miszczak
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my. I feel so stupid :P Yep, it BMP is not supported, thanks for the swift response.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at ImageInputStream and ImageIO.createImageInputStream(File file). By using those properly, you can display BMP image.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49372
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like something which would fit better into our GUIs forum. Moving.
 
Danny Wreczycki
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Miszczak wrote:Oh my. I feel so stupid :P Yep, it BMP is not supported, thanks for the swift response.


Instead of paint method overide paintComponent method. Also I'm not pretty sure but i think BMP is supported today, You can use BufferedImage instead of awt.Image if You like and use ImageIO.read for loading image into memory. In my application developed entirely in swing I have no problems with reading BMP images to be honest.

@edit
Ah and always remeber to dispose Graphics or Graphics2D when not used.

 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Danny Wreczycki wrote:Ah and always remeber to dispose Graphics or Graphics2D when not used.

Buy only those you have created in your code, via Graphics#create(). Do not call dispose() on the passed-in parameter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic