我正在使用jcaptcha所有1.0-Rc6生成captcha映像。
相同的代码片段如下
captchaService = new DefaultManageableImageCaptchaService();
logger.info(" After creating instance getCaptcha ");
long id = System.currentTimeMillis();
String captchaId = String.valueOf(id);
logger.info(" getCaptcha Id " + captchaId);
logger.info("***********Coming into captcha service***************************************************");
BufferedImage challenge = captchaService
.getImageChallengeForID(captchaId);
WritableRaster raster = challenge.getRaster();
ColorModel model = challenge.getColorModel();
challenge.setRGB(0,25,51);
logger.debug("challenge:" + challenge);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(challenge, "jpeg", outputStream);
outputStream.close();
outputStream.flush();
byte[] res = outputStream.toByteArray();
String encodedImage = Base64.encodeBase64String(res);然而,我得到的图像质量不是很高的质量。我们可以做些什么来获得更好的图像质量和更好的可读性。
甚至更改字体样式也是有用的。在这方面的任何帮助也将是有用的。
发布于 2015-08-04 13:34:37
要通过配置更改映像,必须扩展ListImageCaptchaEngine并使用生成器:
并利用它
ImageCaptchaService instance = new DefaultManageableImageCaptchaService(
new FastHashMapCaptchaStore(),
new MyImageCaptchaEngine(),
180,
100000,
75000);发布于 2015-08-04 13:21:04
看看DefaultGimpyEngine如何扩展ListImageCaptchaEngine并提供背景颜色、图像大小、字体等设置(您可以复制该设置并提供自己的值)。
AFAIK字体风格实际上是同一个家族的不同字体(比如"Arial粗体“和"Arial正则”是"Arial“家族的两种风格)。因此,您只能选择所需的字体(确保它们在系统上可用)。
https://stackoverflow.com/questions/31810395
复制相似问题