java实现图片写入高清字体及带边框的方法

时间:2022-06-19 21:59:41

本文实例讲述了java实现图片写入高清字体及带边框的方法。分享给大家供大家参考。具体实现方法如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Graphics2D g2=image.createGraphics();
//g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
//shadowGraphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
FontRenderContext frc = g2.getFontRenderContext();
TextLayout tl = new TextLayout("网址:", new Font("宋体", Font.PLAIN,14), frc);
Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(5,25));
g2.setStroke(new BasicStroke(3.0f));
g2.setColor(Color.WHITE);
g2.draw(sha);
g2.setColor(Color.BLACK);
g2.fill(sha);
g2.dispose();

希望本文所述对大家的java程序设计有所帮助。