本文整理汇总了Java中nl.captcha.backgrounds.GradiatedBackgroundProducer类的典型用法代码示例。如果您正苦于以下问题:Java GradiatedBackgroundProducer类的具体用法?Java GradiatedBackgroundProducer怎么用?Java GradiatedBackgroundProducer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GradiatedBackgroundProducer类属于nl.captcha.backgrounds包,在下文中一共展示了GradiatedBackgroundProducer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCaptchaImage
import nl.captcha.backgrounds.GradiatedBackgroundProducer; //导入依赖的package包/类
private void getCaptchaImage(HttpServletRequest request, HttpServletResponse response) throws IOException
{
String seed = request.getParameter("seed");
if (seed == null || seed.isEmpty())
{
response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
return;
}
int seed_;
try
{
seed_ = Integer.parseInt(seed);
}
catch (NumberFormatException i)
{
response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
return;
}
PredictableCaptchaTextProducer producer = new PredictableCaptchaTextProducer(seed_);
final Captcha captcha = new Captcha.Builder(160, 50).addText(producer).addBackground(new GradiatedBackgroundProducer()).addNoise().gimp(new FishEyeGimpyRenderer()).addBorder().build();
CaptchaServletUtil.writeImage(response, captcha.getImage());
}
示例2: doGet
import nl.captcha.backgrounds.GradiatedBackgroundProducer; //导入依赖的package包/类
@Override
public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException,
IOException {
final HttpSession session = req.getSession();
final Captcha captcha = new Captcha.Builder(_width, _height)
.addText()
.addBackground(new GradiatedBackgroundProducer())
.gimp()
.addBackground(new FlatColorBackgroundProducer(new Color(238, 238, 238)))
.addBorder()
.addNoise()
.build();
session.setAttribute(NAME, captcha);
CaptchaServletUtil.writeImage(resp, captcha.getImage());
}
示例3: updateCaptcha
import nl.captcha.backgrounds.GradiatedBackgroundProducer; //导入依赖的package包/类
@At("/captcha/update")
@Ok("raw:image/png")
public BufferedImage updateCaptcha(HttpSession session, @Param("w") int w, @Param("h") int h) {
if (w * h == 0) { //长或宽为0?重置为默认长宽.
w = 200;
h = 60;
}
Captcha captcha = new Captcha.Builder(w, h)
.addText().addBackground(new GradiatedBackgroundProducer())
// .addNoise(new StraightLineNoiseProducer()).addBorder()
.gimp(new FishEyeGimpyRenderer())
.build();
String text = captcha.getAnswer();
session.setAttribute(Toolkit.captcha_attr, text);
return captcha.getImage();
}
示例4: doGet
import nl.captcha.backgrounds.GradiatedBackgroundProducer; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//ColoredEdgesWordRenderer wordRenderer = new ColoredEdgesWordRenderer(COLORS, FONTS);
ColoredEdgesWordRenderer wordRenderer = new ColoredEdgesWordRenderer(COLORS, FONTS, 1f);
Captcha captcha = new Captcha.Builder(_width, _height).addText(wordRenderer)
//.gimp()
.addNoise()
//.addBackground(new GradiatedBackgroundProducer())
//.addBackground(new TransparentBackgroundProducer())
//.addBackground(new FlatColorBackgroundProducer(Color.lightGray))
.addBackground(new GradiatedBackgroundProducer(Color.lightGray, Color.white))
.build();
CaptchaServletUtil.writeImage(resp, captcha.getImage());
req.getSession().setAttribute(NAME, captcha);
}
示例5: doGet
import nl.captcha.backgrounds.GradiatedBackgroundProducer; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ColoredEdgesWordRenderer wordRenderer = new ColoredEdgesWordRenderer(COLORS, FONTS);
Captcha captcha = new Captcha.Builder(_width, _height).addText(wordRenderer)
.gimp()
.addNoise()
.addBackground(new GradiatedBackgroundProducer())
.build();
CaptchaServletUtil.writeImage(resp, captcha.getImage());
req.getSession().setAttribute(NAME, captcha);
}
示例6: createCaptcha
import nl.captcha.backgrounds.GradiatedBackgroundProducer; //导入依赖的package包/类
/**
* Creates a {@link Captcha} and stores it in the session.
*
* @param width the width of the image
* @param height the height of the image
* @return {@link BufferedImage} containing the captcha image
*/
public BufferedImage createCaptcha(int width, int height)
{
Captcha captcha = new Captcha.Builder(width, height).addText()
.addBackground(new GradiatedBackgroundProducer())
.gimp()
.addNoise()
.addBorder()
.build();
session.setAttribute(Captcha.NAME, captcha);
return captcha.getImage();
}