1

次のようなファイルから JEditorPane に画像をインライン化 (埋め込み) しようとしています。

<img src="data:image/gif;utf-8,data..."> 

しかし、私はコードに苦労しています。

これまでのところ(gifファイルを想定):

try
{
    File imageFile = new File("C:\\test\\testImage.gif"); 
    File htmlFile = new new File("C:\\test\\testOutput.html");

    byte[] imageBytes = Files.toByteArray(imageFile);
    String imageData = new String(imageBytes, "UTF-8");

    String html = "<html><body><img src=\"data:image/gif;utf-8," + imageData + "\"></body></html>";

    FileUtils.writeStringToFile(htmlFile, htmlText);

} catch (Exception e) {
    e.printStackTrace();
}

これはファイルを作成しますが、画像は無効です。私は画像を適切な方法で変換していないと確信しています...

4

1 に答える 1