本文整理匯總了Java中java.awt.geom.Rectangle2D.getBounds方法的典型用法代碼示例。如果您正苦於以下問題:Java Rectangle2D.getBounds方法的具體用法?Java Rectangle2D.getBounds怎麽用?Java Rectangle2D.getBounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.geom.Rectangle2D
的用法示例。
在下文中一共展示了Rectangle2D.getBounds方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateFontImage
import java.awt.geom.Rectangle2D; //導入方法依賴的package包/類
protected BufferedImage generateFontImage(Font font, boolean antiAlias, boolean fractionalMetrics, CharData[] chars)
{
int imgSize = (int) this.imgSize;
BufferedImage bufferedImage = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
g.setFont(font);
g.setColor(new Color(255, 255, 255, 0));
g.fillRect(0, 0, imgSize, imgSize);
g.setColor(Color.WHITE);
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAlias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
FontMetrics fontMetrics = g.getFontMetrics();
int charHeight = 0;
int positionX = 0;
int positionY = 1;
for (int i = 0; i < chars.length; i++)
{
char ch = (char) i;
CharData charData = new CharData();
Rectangle2D dimensions = fontMetrics.getStringBounds(String.valueOf(ch), g);
charData.width = (dimensions.getBounds().width + 8);
charData.height = dimensions.getBounds().height;
if (positionX + charData.width >= imgSize)
{
positionX = 0;
positionY += charHeight;
charHeight = 0;
}
if (charData.height > charHeight)
{
charHeight = charData.height;
}
charData.storedX = positionX;
charData.storedY = positionY;
if (charData.height > this.fontHeight)
{
this.fontHeight = charData.height;
}
chars[i] = charData;
g.drawString(String.valueOf(ch), positionX + 2, positionY + fontMetrics.getAscent());
positionX += charData.width;
}
return bufferedImage;
}