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