0

I am trying to get the images (blob) from DB and adding it to a tableview JavaFX

enter image description here

But the quality is drastically reducing, even color is inverted. Any solution for this?

My code :

Main Form

for (StudentDTO s : studentDTOS) {
                        ImageView img = ImageController.blobToImage(s.getImage());
                        Button btn = new Button("Edit");
                        tmList.add(new ReceptionistStudentTM(
                                s.getId(),
                                img,
                                s.getName(),
                                s.getEmail(),
                                s.getNic(),
                                s.getScholaMark(),
                                s.isStatus(),
                                btn
                        ));
                    }
    tblStudents.setItems(tmList);

ImageController.java

public class ImageController {
    public static ImageView blobToImage(Blob blob) throws SQLException {
        return  new ImageView(new Image(blob.getBinaryStream()));
    }
}

Thanks for your time

nethsrk
  • 78
  • 8
  • 3
    How is it encoded? (Or how are you putting the image data into the database?) To be passed directly to the `Image` constructor, it needs to be in one of the supported formats, as specified in the [documentation](https://openjfx.io/javadoc/19/javafx.graphics/javafx/scene/image/Image.html). – James_D Nov 16 '22 at 17:43
  • 2
    Make sure you are using a recent (e.g. 19) version of JavaFX. [Early JavaFX versions had problems decoding some images](https://stackoverflow.com/questions/9340569/jpeg-image-with-wrong-colors). – jewelsea Nov 16 '22 at 19:45
  • 1
    The Image class has error handling (see the javadoc), try checking it to see if it recorded any errors. – jewelsea Nov 16 '22 at 19:46
  • 2
    Take the stream, save it to a file and see if you can open it in an image rendering program (e.g. a browser). – jewelsea Nov 16 '22 at 19:47
  • I am heavily using this without problems. As others have already suggested, this problem must be related to some encoding problem with your data. – mipa Feb 07 '23 at 08:19

0 Answers0