Question

After going through many similar looking questions I had no way but put my own question here.

I need to display an image on swing application. The source of image is bitmap data which is retrieved from MS SQL server. I have tried the following ways

TRY 1 - I have tried creating an ImageIcon from the bytes retrieved. No results.

TRY 2 - Saved the bytes in a .png file and tried loading Using ImageIO. This works fine on my local machine but fails on test server. Both are windows machines.

TRY3 - On step 2 I tried saving in different formats than .png. It does not work at all.

Please let me know what am I missing?

NOTE : I have tried including jai jars into the Referenced Libraries also.

Was it helpful?

Solution

You should have stored a hint what format the data has in the database. If not, you can only hope that ImageIO can handle it.

There is no need to write the data to files (which is a pitfall in itself, where would you write them? Think of restricted process privileges and disk quotas). Just create an InputStream that accesses the data directly (e.g. java.io.ByteArrayInputStream), that way you can have ImageIO load directly using the stream based methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top