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


Java RenderingHints.add方法代碼示例

本文整理匯總了Java中java.awt.RenderingHints.add方法的典型用法代碼示例。如果您正苦於以下問題:Java RenderingHints.add方法的具體用法?Java RenderingHints.add怎麽用?Java RenderingHints.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.RenderingHints的用法示例。


在下文中一共展示了RenderingHints.add方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: render

import java.awt.RenderingHints; //導入方法依賴的package包/類
@Override
public BufferedImage render(final BufferedImage baseImage) {

    int width = baseImage.getWidth();
    int height = baseImage.getHeight();

    // create an opaque image
    RenderingHints hints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_OFF);

    hints.add(new RenderingHints(RenderingHints.KEY_COLOR_RENDERING,
            RenderingHints.VALUE_COLOR_RENDER_QUALITY));
    hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY));

    hints.add(new RenderingHints(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY));

    BufferedImage imageWithBackground = new BufferedImage(width, height,
            BufferedImage.TYPE_INT_RGB);

    Graphics2D graph = (Graphics2D) imageWithBackground.getGraphics();
    graph.setRenderingHints(hints);
    graph.setPaint(new GradientPaint(0, 0, colorFrom, width, height, colorTo));
    graph.fill(new Rectangle2D.Double(0, 0, width, height));
    graph.drawImage(baseImage, 0, 0, null);
    graph.dispose();

    return imageWithBackground;
}
 
開發者ID:febit,項目名稱:febit,代碼行數:32,代碼來源:GradientBackgroundFilter.java

示例2: render

import java.awt.RenderingHints; //導入方法依賴的package包/類
@Override
public void render(BufferedImage image, String word) {
    final int width = image.getWidth();
    final int height = image.getHeight();
    Graphics2D graphics2D = image.createGraphics();

    RenderingHints hints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    hints.add(new RenderingHints(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY));
    graphics2D.setRenderingHints(hints);

    char[] wordChars = word.toCharArray();
    int wordLen = wordChars.length;

    Font[] chosenFonts = new Font[wordLen];
    int[] charWidths = new int[wordLen];
    int widthNeeded = 0;

    int maxFontSize = 0;

    for (int i = 0; i < wordLen; i++) {
        Font font = RandomUtil.rnd(fonts);

        if (font.getSize() > maxFontSize) {
            maxFontSize = font.getSize();
        }

        FontMetrics fontMetrics = graphics2D.getFontMetrics(font);
        int charWidth = fontMetrics.charWidth(wordChars[i]);
        widthNeeded = widthNeeded + charWidth;
        chosenFonts[i] = font;
        charWidths[i] = charWidth;
    }
    widthNeeded += charSpace * (wordLen - 1);

    int startPosX = (width - widthNeeded) / 2;
    int startPosY = (height - maxFontSize) / 5 + maxFontSize;

    for (int i = 0; i < wordLen; i++) {
        graphics2D.setFont(chosenFonts[i]);
        graphics2D.setColor(RandomUtil.rnd(colors));
        graphics2D.drawString(String.valueOf(wordChars[i]), startPosX, startPosY);
        startPosX = startPosX + charWidths[i] + charSpace;
    }
}
 
開發者ID:febit,項目名稱:febit,代碼行數:48,代碼來源:DefaultWordRender.java


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