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.
IndexProcessing DevelopmentLibraries,  Tool Development › trouble with Tango Project SVG icons
Page Index Toggle Pages: 1
trouble with Tango Project SVG icons (Read 587 times)
trouble with Tango Project SVG icons
Jan 7th, 2008, 11:12pm
 
I would like to read the Tango Project icon theme icons in SVG format into Processing.

See
http://tango-project.org

Unfortunately the Candy SVG renderer pukes on most if not all of the SVG files, e.g.

Code:

import processing.candy.*;
import processing.xml.*;

SVG svg;

void setup()
{
size(400, 400);
background(210);
noLoop();
svg = new SVG(this, "computer.svg");
}

void draw()
{
svg.draw();
}

throws


java.lang.ArrayIndexOutOfBoundsException:  1
at java.awt.geom.AffineTransform.<init>(Unknown Source)
at processing.candy.SVG.parseTransform(SVG.java:1072)
...

OK, so Candy has its limitations.  Next I tried building a library from my own java project built on Apache Batik.

http://dishevelled.org/iconbundle-tango

http://xmlgraphics.apache.org/batik/

It reads the SVG files as expected but the image copy

Code:

Image image = ...;
PImage pImage = new PImage(image);

loses the transparency in the AWT image.

Code:

import java.awt.Image;

import org.dishevelled.iconbundle.*;
import org.dishevelled.iconbundle.tango.*;

PImage pImage;

void setup()
{
size(400, 400);
background(240);
noLoop();
IconBundle iconBundle = TangoProject.COMPUTER;
Image image = iconBundle.getImage(null, IconTextDirection.LEFT_TO_RIGHT, IconState.NORMAL, TangoProject.LARGE);
pImage = new PImage(image);
}

void draw()
{
image(pImage, 20, 20);
}

These examples using BufferedImage

Code:

import java.awt.Color;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

PImage pImage;

void setup()
{
size(400, 400);
background(240);
noLoop();
BufferedImage bufferedImage = new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bufferedImage.createGraphics();
g.setPaint(new Color(0, 0, 0, 100));
g.fillRect(0, 0, 300, 300);
g.dispose();
pImage = new PImage(bufferedImage);
}

void draw()
{
image(pImage, 20, 20);
}

and ImageIO

Code:

import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

String file = ".../data/trans.png";
PImage pImage;

void setup()
{
size(400, 400);
background(240);
noLoop();
try {
Image image = ImageIO.read(new File(file));
pImage = new PImage(image);
} catch (IOException e) {
println(e.getMessage());
}
}

void draw()
{
image(pImage, 20, 20);
}

show the same problem.
Re: trouble with Tango Project SVG icons
Reply #1 - Jan 8th, 2008, 12:45am
 
i had the same issues with the alpha, creating PImages from BufferedImages. I solved the problem using a System.arraycopy() from the bufferedImage.getRGB(...) to the PImage.pixels.

Quote:
PImage pImage = new PImage(bufferedImage.getWidth(), bufferedImage.getHeight(), ARGB);
 int[] newPixels = bufferedImage.getRGB(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null, 0, bufferedImage.getWidth());
 System.arraycopy(newPixels, 0, pImage.pixels, 0, newPixels.length);
Re: trouble with Tango Project SVG icons
Reply #2 - Jan 8th, 2008, 9:35pm
 
Thanks, but that leaves me with a NPE:

java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:2124)
at processing.core.PApplet.image(PApplet.java:7573)

I will take a look at the source for PGraphics/PImage and investigate.
Re: trouble with Tango Project SVG icons
Reply #3 - Jan 8th, 2008, 10:58pm
 
it works for me:

Quote:
import java.awt.Color;
import java.awt.Image;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

PImage pImage;

void setup()
{
 size(400, 400);
 background(240);
 
 BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
 Graphics2D g = bufferedImage.createGraphics();
 g.setPaint(new Color(0, 0, 0, 100));
 g.fillRect(0, 0, 200, 200);
 g.dispose();

 pImage = new PImage(bufferedImage.getWidth(), bufferedImage.getHeight(), ARGB);
 int[] newPixels = bufferedImage.getRGB(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null, 0, bufferedImage.getWidth());
 System.arraycopy(newPixels, 0, pImage.pixels, 0, bufferedImage.getWidth()* bufferedImage.getHeight());
}

void draw()
{
 background(240);
 image(pImage, width/2-pImage.width/2, height/2-pImage.height/2);
 image(pImage, mouseX-pImage.width/2, mouseY-pImage.height/2);
}


Re: trouble with Tango Project SVG icons
Reply #4 - Jan 9th, 2008, 12:12am
 
Thanks, you're right.  I just quickly pasted your example and didn't notice that pImage was redefined locally.

Perhaps this should be added to PImage as a static method or an additional constructor?
Page Index Toggle Pages: 1