We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Using the Java Icon in PDF
Page Index Toggle Pages: 1
Using the Java Icon in PDF (Read 415 times)
Using the Java Icon in PDF
Jun 9th, 2008, 7:25pm
 
I'm trying out this:
import processing.pdf.*;

import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;
Icon icon;

void setup(){
size(100,100,PDF,"test.pdf");
FileSystemView view = FileSystemView.getFileSystemView();      
icon = view.getSystemIcon(new File(dataPath("pdf.png")));
}
void draw()
{
icon.paintIcon(this,this.getGraphics(), 10,10);
exit();
}


But it doesn't work.. any ideas?

thanks
Re: Using the Java Icon in PDF
Reply #1 - Jun 9th, 2008, 8:26pm
 
that's mixing awt with processing, which you cannot do. convert the icon to a PImage, then draw it.
Re: Using the Java Icon in PDF
Reply #2 - Jun 10th, 2008, 8:56am
 
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
Page Index Toggle Pages: 1