JavaFX 图像取消后台加载
JavaFX Image cancel background loading
简而言之;有没有办法取消/清除 JavaFX 图像的后台加载?
在我的代码中,我加载了一堆图像。出于性能原因,这些正在后台加载
public Image(String url, boolean backgroundLoading)
来自图像 class。
问题在于,有时用户交互会导致程序在加载之前的图像完成之前更新图像列表(并且不需要之前的图像)。那时我想取消以前的后台加载。现在,它仍然加载以前的图像,导致实际需要的图像加载时间更长。
参见下面的示例。当我在旧的源流完成处理之前获得新的源流时,内容开始显示图像需要更长的时间,因为它仍在加载以前的源流(至少这是我的猜测)。
List<ImageView> images = sources.map(source -> {
ImageView iv = new ImageView(new Image(source.toUri().toString(), true));
iv.setPreserveRatio(true);
return iv;
}).collect(Collectors.toList());
content.getChildren().setAll(images);
您可以使用 Image.cancel
取消 Image
的后台加载。
Cancels the background loading of this image.
Has no effect if this image isn't loaded in background or if loading has already completed.
简而言之;有没有办法取消/清除 JavaFX 图像的后台加载?
在我的代码中,我加载了一堆图像。出于性能原因,这些正在后台加载
public Image(String url, boolean backgroundLoading)
来自图像 class。
问题在于,有时用户交互会导致程序在加载之前的图像完成之前更新图像列表(并且不需要之前的图像)。那时我想取消以前的后台加载。现在,它仍然加载以前的图像,导致实际需要的图像加载时间更长。
参见下面的示例。当我在旧的源流完成处理之前获得新的源流时,内容开始显示图像需要更长的时间,因为它仍在加载以前的源流(至少这是我的猜测)。
List<ImageView> images = sources.map(source -> {
ImageView iv = new ImageView(new Image(source.toUri().toString(), true));
iv.setPreserveRatio(true);
return iv;
}).collect(Collectors.toList());
content.getChildren().setAll(images);
您可以使用 Image.cancel
取消 Image
的后台加载。
Cancels the background loading of this image.
Has no effect if this image isn't loaded in background or if loading has already completed.