I want to convert some arbitrary text to a Shape (java.awt.Shape) and then stroke/fill the Shape to draw it. How can I do this?
If I understood you correctly, this is not to address your exact answer, but it's a start...
//Rough pseudo code
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.TexturePaint;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = (Graphics2D)image.getGraphics();
//Paint with texturing brush
Rectangle2D rect2D = new Rectangle2D.Double(0, 0, width, height);
graphics.setPaint(new TexturePaint(image, rect2D));
graphics.fill(rect2D);
//Draw text
graphics.drawString("my text goes here", xPos, yPos);
In Summary,
BufferedImage
object of width
and height
and ImageType
.Graphics
object.