我在zul页面上有一张图片,需要使用控制器替换。
我尝试使用Image.setContent(bufferedImage)以及Image.setSrc(base64EncodedString)都不更新显示的图像。
我还尝试在设置源和内容之后调用Image.invalidate(),这也不会更新图像。
我在.zul上的图片标签看起来像这样
<image id="imgStreaming" width="200" height="200" style="display:inline-block; border:1px solid #b9b9b9; border-radius:0px; color:#ccc; min-width:200px; min-height:200px;" />
控制器中的代码如下所示
JsonArray ja = json.getAsJsonObject().get("A").getAsJsonArray();
BufferedImage bufferImg = decodeToImage(ja.get(0).toString());
imgStreaming.setContent(bufferImg);
imgStreamingFingerprint.invalidate();
该decodeToImage方法只采用base64字符串,并将其转换回BufferedImage
最佳答案
ZK图像内容包含AImage对象。因此,您需要先创建此对象,然后才能更改图像元素的内容。
见下面的例子
<image content="@bind(vm.currentImage)"/>
URL url = new URL(IMAGE_URL);
currentImage = new AImage(url);
关于java - ZK替换图片内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49550117/