Java
[SWT] jar파일 안에 있는 이미지 로드
튼튼한노예
2015. 4. 27. 10:43
public static Image loadImage(String path, boolean inJar)
{
Image newImage = null;
try
{
if(inJar)
{
newImage = new Image(null, YOUR_MAIN_CLASS.class.getClassLoader().getResourceAsStream(path));
}
else
{
newImage = new Image(null, path);
}
}
catch(SWTException ex)
{
System.out.println("Couldn't find " + path);
e.printStackTrace();
}
return newImage;
}
getResourceAsStream(path) 함수를 이용해 불러와야 한다.
ResourceAsStream이 아닌 Resource는 URL만 리턴할 뿐이다.