使用Java获取文件图标的特定版本 [英] Get a specific version of the icon of a file in Java

查看:219
本文介绍了使用Java获取文件图标的特定版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看这个问题我是看第一个答案。

I was looking at this question and I was looking at the first answer.

所以我尝试使用这段代码:

So I tried to use this code:

public static Image getIcon(String fileName) throws Exception {
    File file = new File(fileName);
    FileSystemView view = FileSystemView.getFileSystemView();
    Icon icon = view.getSystemIcon(file);
    ImageIcon imageIcon = (ImageIcon) icon;
    Image image = imageIcon.getImage();
    return image;
}

哪个会返回图片(或抛出错误)但图像的分辨率非常低。

Which does return an Image (or throws an Error) but the Image has terribly low resolution.

我假设这是因为返回了 16x16 Image

I am assuming that this is because the 16x16 Image is returned.

有没有办法说明哪些图像我想要退回?

Is there any way to state which Image I want to be returned?

推荐答案

Java为您提供了两种检索文件图标的可能性。

您已经知道第一个:

Java offers you two possibilities to retrieve file icons.
You already know the first one:

Icon icon = FileSystemView.getFileSystemView().getSystemIcon(new File(FILENAME));

为您提供16x16像素的结果。


另一个使用 ShellFolder

that gives you a 16x16 pixel result.

The other one using ShellFolder

Icon icon = new ImageIcon(ShellFolder.getShellFolder(new File(FILENAME)).getIcon(true));

将根据布尔标志 getLargeIcon检索较大的(32x32) getIcon 方法中的

我很抱歉,但更多(目前)不可能java默认库。您可以阅读此JDK错误报告中的兴趣。
但到目前为止还没有任何工作。


如果你真的想拥有更大的版本,你需要使用操作系统检索它们,具体取决于本机调用,或者将它们手动存储为本地应用程序资源。


注意:如果您在访问 ShellFolder 时遇到问题,请阅读这个问题

will retrieve you the larger one (32x32) depending on the boolean flag getLargeIcon in the getIcon method.
I'm sorry for you but more is (at the moment) not possible with the java default libraries. Interest exists as you can read in this JDK bugreport. But nothing has been done so far.

If you really want to have larger versions you will need to retrieve them with the OS depending native calls or store them manually as local application ressources.

Note: If you have problems accessing ShellFolder you should read this question.

这篇关于使用Java获取文件图标的特定版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆