Loading icon from filesystem

已计划

Hi,

I need to load an Svg icon from filesystem, but so far my attempts failed. I want to use it in FileIconProvider to display user project icons in Monorepos.

Icons imported from resources using IconLoader.getIcon work without any issues, hower if I try to use it on outside file there it doesn't work and icon is null.

I tried to use prefix like “file:”, combinations of paths to file and still no success.

I also tried to load the Icon as an ImageIcon but passing it as Icon displays nothnig, icon has width -1. (when wrong path is provided it throws exception, so at least it reads the file)

 

class File_Icon_Example: FileIconProvider {
  override fun getIcon(file: VirtualFile, flags: Int, 
  	project: Project?): Icon? {
    val bufferedInputStream = 
    	BufferedInputStream(FileInputStream("/Users/jarek/icos/npm.svg"))
    val icon = ImageIcon(bufferedInputStream.readBytes())
    return icon
    // this code below works correctly
    // return Icons.npm
  }

}

Any idea how could this be fixed?

0

请先登录再写评论。