獲取字符串像素

獲取字符串像素

Pixel length of String
import java.awt.FontMetrics;
import java.awt.geom.Rectangle2D;

1. awt
 Font font = new Font("Verdana", Font.PLAIN, 10); 
 FontMetrics metrics = new FontMetrics(font) { 
 }; 
 Rectangle2D bounds = metrics.getStringBounds("string", null); 
 int widthInPixels = (int) bounds.getWidth(); 

文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/3_program/java/javajs/20091214/184739.html

你可能感兴趣的:(獲取字符串像素)