當前位置: 首頁>>代碼示例>>Java>>正文


Java Rectangle2D.getBounds方法代碼示例

本文整理匯總了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;
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:53,代碼來源:CFont.java


注:本文中的java.awt.geom.Rectangle2D.getBounds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。