请问Mac OS X上怎么取得系统文件(例如,Desktop)的图标图像

chenweionline 2008-01-19 05:55:26
请问Mac OS X上怎么取得系统文件(例如,Desktop)的图标图像?

Icon icon = FileSystemView.getFileSystemView().getSystemIcon(getFile());
这里得到的 icon 是个apple.laf.CUIAquaIcon 类对象,没有 getImage() 方法。
...全文
118 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenweionline 2008-01-20
  • 打赏
  • 举报
回复
谢谢楼上,我使用这个方法得到的都是文件夹图标。不知道有没有方法能够取得系统文件的特殊图标?
hotjar 2008-01-19
  • 打赏
  • 举报
回复
Oh, BufferedImage is an Image actually. Maybe you needn't to get it exported to a image file.

I haven't got OS 10 on hand, but the interface is all the same on any platform.

Have fun.
hotjar 2008-01-19
  • 打赏
  • 举报
回复
Try this:

Icon icon = FileSystemView.getFileSystemView().getSystemIcon(getFile());
int width = icon.getIconWidth();
int height = icon.getIconHeight();
BufferedImage img = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
icon.paintIcon(null, g, 0, 0);
try {
ImageIO.write(img, "jpg", new File("c:/1.jpg"));
} catch (IOException e) {
// Make it silent here.
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧