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.