Vaadin 添加iamge组件用流生成二维码

最近在看Vaadin  需要用Vaadin 做一个二维码  选用了Zing 谷歌的生成包;

参考下面的VaadinAPI

// Create the stream resource with some initial filename
StreamResource imageResource =
new StreamResource(imageSource, "initial-filename.png");
// Instruct browser not to cache the image
imageResource.setCacheTime(0);
// Display the image
Image image = new Image(null, imageResource);
刷新时, 你还需要对 Image 对象调用 markAsDirty() 方法.
// This needs to be done, but is not sufficient
image.markAsDirty();
// Generate a filename with a timestamp
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String filename = "myfilename-" + df.format(new Date()) + ".png";
// Replace the filename in the resource
imageResource.setFilename(makeImageFilename());
然而上面代码并未用什么用   参考api后修改为
String token=new Md5PasswordEncoder().encodePassword(new Date().toString(),username+password);
				identityService.setUserToken(username,token);
				StreamResource.StreamSource imagesource = new MyImageSource(token);
				StreamResource resource = new StreamResource(imagesource, "myimage.png", ExplorerApp.get());
				Embedded image = new Embedded(null, resource);
				image.setHeight("100%");
				image.setWidth("100%");
				form_image.getLayout().removeAllComponents();
				form_image.getLayout().addComponent(image);


这文档还是挺坑人的 在StreamResource方法时必须有application参数

然后就是image组件 大家可以试试 vaadin中并没有直接用的image组件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值