开发者

Is there a maximum font size for Java Graphics2D?

I am creating image tiles in Java, and require to create very large texts (font sizes over 200,000...) However, it seems that when the font size reaches over a certain threshold, the Graphics engine in Java (JDK1.6.0.18) no longer draws the string correctly. On my Win7/64 environment it seems I can only print Helvetica characters up to 27915 pixel size.

Is there a way around this? How can I draw such large characters? Am I doing something wrong? Is this a known limitation?

A sample application:

    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import com.sun.image.codec.jpeg.*;

    public class FontTest {



public static void main(String[] args) throws Exception {
        BufferedImage image = new BufferedImage(1000,1000,BufferedImage.TYPE_INT_RGB);
        Graphics2D g = Zoomer.getGraphics(image);

        int fontsize = 2开发者_Go百科7916;
        Font font = new Font("Helvetica",Font.PLAIN,fontsize);
        g.setFont(font);
        g.setColor(Color.YELLOW);

        g.drawString("Z", 5, 990);

        JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(new FileOutputStream(new File("image."+fontsize+".jpg"),false));
        JPEGEncodeParam param = jpeg.getDefaultJPEGEncodeParam(image);
        jpeg.encode(image);
        System.out.println("Ready with fontsize:"+fontsize);
    }

Any image up to 27915 displays the left bottom part of the Z correctly, but for 27915 and higher, it displays it backward somehow.

Sample of the wrong image (with the yellow to the left i/o the right: size=27,916


Which JDK version are you using? Try the latest JDK 6 release as well as the latest JDK 7 beta. Or use Apache Batik instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜