本文整理汇总了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;
}