Java2D Performance Issues

I think I found a solution by researching and putting bits and pieces together from too many Google searches. Here it is, comments and all: private BufferedImage toCompatibleImage(BufferedImage image) { // obtain the current system graphical settings GraphicsConfiguration gfxConfig = GraphicsEnvironment. getLocalGraphicsEnvironment().getDefaultScreenDevice(). getDefaultConfiguration(); /* * if image is already compatible and optimized for current system … Read more

How do i align this text correctly?

Here’s a simple example of rotating text. Addendum: You’ll want to adjust the the text’s radial starting point by stringWidth(name[n]). Your program appears to be rotating individual characters in a effort to follow the arc, while the example appears to be drawing the text in a straight line tangent to the arc. The latter approach … Read more

setOpaque(true/false); Java

The short answer to your question is that “opaque” is defined in English as completely non-transparent. Therefore an opaque component is one which paints its entire rectangle, and every pixel is not at all translucent to any degree. However, the Swing component opacity API is one of those mis-designed and therefore often mis-used APIs. What’s … Read more

How to resize text in java

One way is to use an AffineTransform (this variant also fades the color). import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import javax.swing.*; import java.io.File; import javax.imageio.ImageIO; public class StretchText { public static void main(String[] args) throws Exception { // used to stretch the graphics instance sideways AffineTransform stretch = new AffineTransform(); int w = 640; // … Read more

Java2D Graphics anti-aliased

Assuming you actually want smooth (non-aliased) text, TextLayout may make this easier. The FontRenderContext constructor can manage the anti-aliasing and fractional metrics settings. Addendum: Using g2d.setColor(Color.blue) seems to produce the expected effect. Addendum: On Mac OS X, the Pixie application in /Developer/Applications/Graphics Tools/ is convenient for examining the anti-alias pixels. On other platforms, Zoom may … Read more

Smoothing a jagged path

This is a big subject. You might find Depixelizing Pixel Art1 by Johannes Kopf & Dani Lischinski useful: it’s readable, recent, includes a summary of previous work, and explains their approach in detail. See also slides covering similar background and video(!). Here are some screenshots from the document of ‘nearest neighbor’ vs. ‘their technique’.