【发布时间】:2014-10-04 12:30:16
【问题描述】:
我正在尝试从文件 (.ico/.exe) 中读取缩略图(图标;32x32px)并将其设置为 JavaFX 标签。
我的第一次尝试:
public Icon getLargeIcon(String exeFile) {
if (exeFile != null) {
File file = new File(exeFile);
try {
ShellFolder sf = ShellFolder.getShellFolder(file);
return new ImageIcon(sf.getIcon(true), sf.getFolderType());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
return null;
}
之后我会这样做:
Icon largeIcon = getLargeIcon(file.getAbsolutePath());
ImageIcon swingImageIcon = (ImageIcon) largeIcon;
java.awt.Image awtImage = swingImageIcon.getImage();
Image fxImage = javafx.scene.image.Image.impl_fromPlatformImage(awtImage);
lblAppIconValue.setGraphic(new ImageView(fxImage));
我搜索了几个网站并找到了这个,但它给了我一个例外:
java.lang.UnsupportedOperationException: unsupported class for loadPlatformImage
我的第二次尝试:
URL url = file.toURI().toURL();
Image image = new Image(url.toString());
lblAppIconValue.setGraphic(new ImageView(image));
也不行……
我的问题:如何将 javax.swing.Icon 设置为 JavaFX 标签?是否可以?如果不可能,如何从文件中读取缩略图并将其设置为 JavaFX 标签的图标/图形?
谢谢!
【问题讨论】: