Java – convert characters or strings to shapes / regions
I want to be able to convert any character or string into a shape or area so that I can draw the character in any size, style, effect, etc I like it.
More specifically, I'll draw it with parallax so that it's clearly defined only from a certain angle (that's why I can't use HTML or anything of that nature) I've set parallax. I just need this shape
In short, common shape conversion (char c) {...}
Or, if you can think of another way, please let me know
Just to give you a rough idea:
Solution
According to the previous answer, it seems that you can manage it as follows (assuming that this method is defined on a subclass of JPanel):
public Shape convert(char c) {
Font f = getFont();
// Optionally change font characteristics here
// f = f.deriveFont(Font.BOLD,70);
FontRenderContext frc = getFontMetrics(f).getFontRenderContext();
GlyphVector v = f.createGlyphVector(frc,new char[] { c });
return v.getOutline();
}
It may be easier to declare methods to get string parameters because you can pass string as the second parameter to createglyphvector () – this may be more effective than converting each character individually if you need to perform multiple operations
