我将图像保存在字符串中,然后当我打开它时它总是 300x150
为什么图像被截断?
300x150 从何而来?
代码就是你所看到的。只需 2 个按钮。
第一个将图像保存在“png”中,另一个从“png”中读取图像
Button save = new Button("copy");
save.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ImageElement imageElement = ImageElement.as(image.getElement());
Canvas canvasTmp = Canvas.createIfSupported();
Context2d context = canvasTmp.getContext2d();
context.drawImage(imageElement, 0.0, 0.0, imageElement.getWidth(), imageElement.getHeight());
png = canvasTmp.toDataUrl("image/png");
}
});
Button open = new Button("open");
open.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
final Image image = new Image(png);
vp.add(image);
image.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event)
{
Window.alert("ok");
}
});
image.addErrorHandler(new ErrorHandler() {
@Override
public void onError(ErrorEvent event) {
Window.alert("error");
}
} );
}
});