set anti-aliasing

This commit is contained in:
hrj 2019-06-08 11:21:13 +05:30
parent c047691424
commit 715b9e4206
2 changed files with 7 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package lc;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
@ -15,6 +16,8 @@ public class GifCaptcha implements ChallengeProvider{
BufferedImage img = new BufferedImage(250, 100, BufferedImage.TYPE_INT_RGB);
Font font = new Font("Bradley Hand", Font.ROMAN_BASELINE, 48);
Graphics2D graphics2D = img.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics2D.setFont(font);
graphics2D.setColor(new Color((int)(Math.random() * 0x1000000)));
graphics2D.drawString( text , 45, 45);

View File

@ -2,6 +2,7 @@ package lc;
import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Color;
import java.awt.Font;
import java.awt.font.TextLayout;
@ -24,6 +25,9 @@ public class ShadowTextCaptcha implements ChallengeProvider{
BufferedImage img = new BufferedImage(350, 100, BufferedImage.TYPE_INT_RGB);
Font font = new Font("Arial",Font.ROMAN_BASELINE ,48);
Graphics2D graphics2D = img.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
TextLayout textLayout = new TextLayout(text, font, graphics2D.getFontRenderContext());
HelperFunctions.setRenderingHints(graphics2D);
graphics2D.setPaint(Color.WHITE);