I've just watched the link as http://simplecaptcha.sourceforge.net/ and it gives demo of some images showing that captcha can be designed as a colored one so it can be not only black and white one. But for some reason I couldn't find any tutorials of how control SimpleCaptcha colors :( If you know some snippets or tutorials share them please.
All useful comments are appr开发者_Go百科eciated :)
Which part do you want to be in color? You can, for example, control the color of the text via a WordRenderer
. Examples of how to use their Captcha.Builder
can be found on their website. You can add things like the following to any of these examples:
List<java.awt.Color> textColors = Arrays.asList(
Color.BLACK, Color.BLUE, Color.RED);
List<java.awt.Font> textFonts = Arrays.asList(
new Font("Arial", Font.BOLD, 40),
new Font("Courier", Font.BOLD, 40));
java.awt.Color backgroundColor = Color.ORANGE;
Captcha captcha = new Captcha.Builder(200, 50)
.addText(
new DefaultTextProducer(),
new DefaultWordRenderer(textColors, textFonts))
.addBackground(new FlatColorBackgroundProducer(backgroundColor))
.build();
DefaultWordRenderer
accepts a List
of colors and fonts so that you can pick from several colors/fonts randomly per request. So, if you provide it with only one color and font, then you'll get those every time. If you provide it with five colors and one font, then you'll get the same font every time, but the color will be selected randomly from the five that you provided.
The example above uses FlatColorBackgroundProducer
, but there are other options, including GradiatedBackgroundProducer
and SquigglesBackgroundProducer
.
Probably using Class ColoredEdgesWordRenderer. Take look at http://simplecaptcha.sourceforge.net/javadocs/index.html
精彩评论