无法将本地图像文件显示为WebEngine图像src属性 [英] Can not display local image file as WebEngine image src attribute

查看:62
本文介绍了无法将本地图像文件显示为WebEngine图像src属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置动态拥有的img标签的src.从eclipse运行时,以下代码有效,但将其导出为正在运行的jar文件后,则无效:

I'm trying to set the src of an img tag I have dynamically. The following piece of code works when running from eclipse but not after exporting it as a running jar file:

doc.getElementById("user-thumb").setAttribute("src", selectedVcard.getThumb().getFilePath());

通过"user-thumb" id获得的元素是图像.返回的thumb对象是一个简单的自定义ImageView,我已对其进行了扩展以容纳更多信息,并使用以下方法对其进行了初始化:

The element got by the "user-thumb" id is an image. The thumb object returned is a simple custom ImageView I've extended to hold more information and is initialized using:

public Thumb(String url) {
    super(url);
    this.setFilePath(url);
    getStyleClass().add("thumb");
}

getFilePath()方法从一个以以下内容开头的临时文件中返回路径:

the method getFilePath() is returning a path from a temporary file starting with:

file:/

但是我已经尝试将其更改为

But I've already tried to change it to

file://

甚至:

file:///

,没有成功.我已经在这里进行了搜索和搜索,但是每个答案都以file://开头.我的代码有问题吗?还是javafx 2?顺便说一句,我正在使用javafx 2.2 GA和来自oracle的jre 1.7.0.6.干杯

and got no success. I have googled and searched here but every answer points to start with file://. Is there something wrong with my code or is it javafx 2? By the way, I'm using javafx 2.2 GA and the jre 1.7.0.6 from oracle. Cheers

推荐答案

您可以使用图片的数据URI

类似...

String imageMimeType = "image/jpeg"; // Replace this for the correct mime of the image
String dataURI = "data:" + imageMimeType + ";base64," + 
     javax.xml.bind.DatatypeConverter.printBase64Binary(imageByteArray);

这篇关于无法将本地图像文件显示为WebEngine图像src属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆