Created
November 11, 2009 08:11
-
-
Save taka2/231778 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.*; | |
| import java.awt.image.*; | |
| import java.io.File; | |
| import javax.imageio.*; | |
| public class JavaTest | |
| { | |
| public static void main(String[] args) throws Exception | |
| { | |
| BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); | |
| Graphics2D g2d = bi.createGraphics(); | |
| String data = "2009/11/11"; | |
| for(int i=1; i<=200; i++) | |
| { | |
| g2d.setFont(new Font("Dialog", Font.PLAIN, i)); | |
| FontMetrics fm = g2d.getFontMetrics(); | |
| int width = 0; | |
| for(int j=0; j<data.length(); j++) | |
| { | |
| width += fm.charWidth(data.charAt(j)); | |
| } | |
| System.out.printf("Font size = %3d(pt), Width = %4d, Height = %4d\n", i, width, fm.getHeight()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment