Reputation: 11559
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
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