Thanks, got it working!
Fully working code for fetching your operating systems file icon as a PImage:
Code:
import processing.pdf.*;
import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;
PImage icon;
int bg;
// PDF TEST
void setup(){
size(100,100,PDF,"test.pdf");
bg = color(255);
icon = getIcon(new File(dataPath("file.pdf")));
}
void draw()
{
background(bg);
image(icon,0,0);
println("Done");
exit();
}
// Fetch filesystem icon
PImage getIcon(File file)
{
int w = 16, h = 16;
BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB);
for(int i = 0; i < w; i++){
for(int j = 0; j < h; j++){
img.setRGB(i,j,color(0,0)); // alpha
}
}
FileSystemView.getFileSystemView().getSystemIcon(file).paintIcon(null,img.getGraphics(), 0,0);
PImage ret = new PImage(w,h,ARGB);
for(int i = 0; i < w; i++){
for(int j = 0; j < h; j++){
int c = img.getRGB(i,j);
if(c == color(0,0)){
// seems alpha doesn't work in pdf, so i set the color to the same as the background
ret.set(i,j,color(red(bg),green(bg),blue(bg),0));
}else{
ret.set(i,j,img.getRGB(i,j));
}
}
}
return ret;
}
-seltar