tmn
tmn

Reputation: 11559

Use BufferedImage in JLabel HTML?

Is it possible I can used a BufferedImage in a JLabel's HTML? Or do I have to save it locally and call it by a file path?

Upvotes: 2

Views: 657

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347334

First, you will need to save the image...

File tmp = File.create("buffer", ".png");
ImageIO.write(img, "png", tmp);

Then you need to use the file's URL as the src attribute to the img tag...

StringBuilder sb = new StringBuilder(128);
sb.append("<html><img src='");
sb.append(tmp.toURI().toURL());
sb.append("'></html>");

Then set that as the text to what ever...

label.setText(sb.toString());
label.setToolTipText(sb.toString());

Upvotes: 3

Related Questions