1

I have an Image object created using

SnapshotParameters para = new SnapshotParameters();
para.setFill(Color.TRANSPARENT);
Image img = myStackPane.snapshot(para, null);

Now, I want to convert it to Base64 image to put it into javafx WebView. But I did not find any method to do it. Can anybody help me please?

1 Answers1

4

Convert Image to byte array such as in this answer. Then use any Base64 library to encode. For example Apache Commons.

EDIT

BufferedImage bImage = SwingFXUtils.fromFXImage(logo.getImage(), null);
ByteArrayOutputStream s = new ByteArrayOutputStream();
ImageIO.write(bImage, "png", s);
byte[] res  = s.toByteArray()
s.close();
Base64.encode(res);
Community
  • 1
  • 1
MBec
  • 2,172
  • 1
  • 12
  • 15